Skip to content

Commit 98b0a88

Browse files
committed
Tons of changes, should have committed sooner, decoded GameSettings
1 parent c2dcedf commit 98b0a88

24 files changed

Lines changed: 737 additions & 275 deletions

ESPSharp/ESPReader.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using System.IO;
7+
using System.Diagnostics;
78

89
namespace ESPSharp
910
{
@@ -34,7 +35,54 @@ public string ReadNullTermString(int length)
3435

3536
public T ReadSimpleSubrecord<T>()
3637
{
37-
throw new NotImplementedException();
38+
string Tag = ReadTag();
39+
int size = ReadUInt16();
40+
41+
string typeT = typeof(T).ToString();
42+
43+
switch (typeT)
44+
{
45+
case "System.Byte":
46+
Debug.Assert(size == 1);
47+
return (T)(object)ReadByte();
48+
case "System.SByte":
49+
Debug.Assert(size == 1);
50+
return (T)(object)ReadSByte();
51+
case "System.Char":
52+
Debug.Assert(size == 1);
53+
return (T)(object)ReadChar();
54+
case "System.UInt16":
55+
Debug.Assert(size == 2);
56+
return (T)(object)ReadUInt16();
57+
case "System.Int16":
58+
Debug.Assert(size == 2);
59+
return (T)(object)ReadInt16();
60+
case "System.UInt32":
61+
Debug.Assert(size == 4);
62+
return (T)(object)ReadUInt32();
63+
case "System.Int32":
64+
Debug.Assert(size == 4);
65+
return (T)(object)ReadInt32();
66+
case "System.Single":
67+
Debug.Assert(size == 4);
68+
return (T)(object)ReadSingle();
69+
case "System.UInt64":
70+
Debug.Assert(size == 8);
71+
return (T)(object)ReadUInt64();
72+
case "System.Int64":
73+
Debug.Assert(size == 8);
74+
return (T)(object)ReadInt64();
75+
case "System.Byte[]":
76+
return (T)(object)ReadBytes(size);
77+
case "System.Char[]":
78+
return (T)(object)ReadChars(size);
79+
case "System.String":
80+
string outString = new String(ReadChars(size - 1));
81+
ReadByte();
82+
return (T)(object)outString;
83+
default:
84+
throw new NotImplementedException(typeT + " is not yet implemented.");
85+
}
3886
}
3987
}
4088
}

ESPSharp/ESPSharp.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
<Compile Include="EnumsAndFlags\RecordFlag.cs" />
6060
<Compile Include="FormID.cs" />
6161
<Compile Include="Group.cs" />
62+
<Compile Include="Interfaces\IEditorID.cs" />
63+
<Compile Include="Interfaces\IReferenceContainer.cs" />
6264
<Compile Include="Records\Header.cs" />
6365
<Compile Include="ISubgroup.cs" />
6466
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -68,7 +70,13 @@
6870
<Compile Include="Groups\WorldGroup.cs" />
6971
<Compile Include="Records\GenericRecord.cs" />
7072
<Compile Include="Records\GameSetting.cs" />
73+
<Compile Include="Records\TextureSet.cs" />
7174
<Compile Include="Subrecord.cs" />
75+
<Compile Include="SubrecordCollection.cs" />
76+
<Compile Include="SubrecordCollection\MasterFileData.cs" />
77+
<Compile Include="Subrecords\DecalData.cs" />
78+
<Compile Include="Subrecords\FormArray.cs" />
79+
<Compile Include="Subrecords\ObjectBounds.cs" />
7280
<Compile Include="Subrecords\PluginHeader.cs" />
7381
<Compile Include="Subrecords\SimpleSubrecord.cs" />
7482
<Compile Include="Subrecords\UndecodedSubrecord.cs" />

ESPSharp/ESPWriter.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,71 @@ public ESPWriter(Stream stream)
1414

1515
public void WriteTag(string Tag)
1616
{
17-
Write(Utility.DesanitizeTag(Tag));
17+
Write(Utility.DesanitizeTag(Tag).ToCharArray());
18+
}
19+
20+
public void WriteSimpleSubrecord<T>(T Value, string Tag)
21+
{
22+
string typeT = typeof(T).ToString();
23+
24+
WriteTag(Tag);
25+
26+
switch (typeT)
27+
{
28+
case "System.Byte":
29+
Write((ushort)1);
30+
Write((byte)(object)Value);
31+
break;
32+
case "System.SByte":
33+
Write((ushort)1);
34+
Write((sbyte)(object)Value);
35+
break;
36+
case "System.Char":
37+
Write((ushort)1);
38+
Write((char)(object)Value);
39+
break;
40+
case "System.UInt16":
41+
Write((ushort)2);
42+
Write((ushort)(object)Value);
43+
break;
44+
case "System.Int16":
45+
Write((ushort)2);
46+
Write((short)(object)Value);
47+
break;
48+
case "System.UInt32":
49+
Write((ushort)4);
50+
Write((uint)(object)Value);
51+
break;
52+
case "System.Int32":
53+
Write((ushort)4);
54+
Write((int)(object)Value);
55+
break;
56+
case "System.Single":
57+
Write((ushort)4);
58+
Write((float)(object)Value);
59+
break;
60+
case "System.UInt64":
61+
Write((ushort)8);
62+
Write((ulong)(object)Value);
63+
break;
64+
case "System.Int64":
65+
Write((ushort)8);
66+
Write((long)(object)Value);
67+
break;
68+
case "System.Byte[]":
69+
Write((ushort)((byte[])(object)Value).Length);
70+
Write((byte[])(object)Value);
71+
break;
72+
case "System.Char[]":
73+
Write((ushort)((char[])(object)Value).Length);
74+
Write((char[])(object)Value);
75+
break;
76+
case "System.String":
77+
Write((ushort)(((string)(object)Value).Length + 1));
78+
Write(((string)(object)Value).ToCharArray());
79+
Write((byte)0);
80+
break;
81+
}
1882
}
1983
}
2084
}

ESPSharp/ElderScrollsPlugin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ElderScrollsPlugin
1515

1616
public void WriteXML(string destinationFolder)
1717
{
18-
Header.WriteXML(Path.Combine(destinationFolder, "0.xml"));
18+
Header.WriteXML(Path.Combine(destinationFolder, "Header.xml"));
1919

2020
foreach (Group group in Groups)
2121
{
@@ -28,7 +28,7 @@ public void WriteXML(string destinationFolder)
2828
public static ElderScrollsPlugin ReadXML(string sourceFolder)
2929
{
3030
ElderScrollsPlugin outPlug = new ElderScrollsPlugin();
31-
outPlug.Header = Record.ReadXML(Path.Combine(sourceFolder, "0.xml"));
31+
outPlug.Header = Record.ReadXML(Path.Combine(sourceFolder, "Header.xml"));
3232

3333
foreach (var folder in Directory.EnumerateDirectories(sourceFolder, "*.*", SearchOption.TopDirectoryOnly))
3434
{

ESPSharp/Extensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public static char[] ToChars(this XElement ele)
8888
{
8989
return ele.Value.ToArray();
9090
}
91+
public static void AddSimpleSubrecord(this XElement ele, string name, string tag, object value)
92+
{
93+
ele.Add(
94+
new XElement(name,
95+
new XAttribute("Tag", tag),
96+
value));
97+
}
9198
#endregion
9299

93100
public static string ToBase64(this byte[] bytes)

ESPSharp/FormID.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static implicit operator uint(FormID val)
2727

2828
public override string ToString()
2929
{
30-
return rawVal.ToString("x");
30+
return rawVal.ToString("X8");
3131
}
3232
}
3333
}

ESPSharp/Groups/TopGroup.cs

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,117 @@
11
using System;
22
using System.IO;
33
using System.Xml.Linq;
4+
using System.Collections.Generic;
45

56
namespace ESPSharp
67
{
78
class TopGroup : Group
89
{
10+
private Dictionary<string, string> tagToNameDictionary = new Dictionary<string, string>
11+
{
12+
{"GMST", "Game Settings"},
13+
{"TXST", "Texture Sets"},
14+
{"MICN", "Menu Icons"},
15+
{"GLOB", "Global Variables"},
16+
{"CLAS", "Classes"},
17+
{"FACT", "Factions"},
18+
{"HDPT", "Head Parts"},
19+
{"HAIR", "Hairs"},
20+
{"EYES", "Eyes"},
21+
{"RACE", "Races"},
22+
{"SOUN", "Sounds"},
23+
{"ASPC", "Audio Spaces"},
24+
{"MGEF", "Magic Effects"},
25+
{"SCPT", "Scripts"},
26+
{"LTEX", "Landscape Textures"},
27+
{"ENCH", "Object Effects"},
28+
{"SPEL", "Actor Effects"},
29+
{"ACTI", "Activators"},
30+
{"TACT", "Talking Activators"},
31+
{"TERM", "Terminals"},
32+
{"ARMO", "Armors"},
33+
{"BOOK", "Books"},
34+
{"CONT", "Containers"},
35+
{"DOOR", "Doors"},
36+
{"INGR", "Ingredients"},
37+
{"LIGH", "Lights"},
38+
{"MISC", "Misc Items"},
39+
{"STAT", "Statics"},
40+
{"SCOL", "Static Collections"},
41+
{"MSTT", "Movable Statics"},
42+
{"PWAT", "Placeable Waters"},
43+
{"GRAS", "Grasses"},
44+
{"TREE", "Trees"},
45+
{"FURN", "Furniture"},
46+
{"WEAP", "Weapons"},
47+
{"AMMO", "Ammunitions"},
48+
{"NPC_", "Non-Player Characters"},
49+
{"CREA", "Creatures"},
50+
{"LVLC", "Leveled Creatures"},
51+
{"LVLN", "Leveled NPCs"},
52+
{"KEYM", "Key Items"},
53+
{"ALCH", "Ingestibles"},
54+
{"IDLM", "Idle Markers"},
55+
{"NOTE", "Notes"},
56+
{"COBJ", "Constructble Objects"},
57+
{"PROJ", "Projectiles"},
58+
{"LVLI", "Leveled Items"},
59+
{"WTHR", "Weathers"},
60+
{"CLMT", "Climates"},
61+
{"REGN", "Regions"},
62+
{"NAVI", "NavMesh Info Map"},
63+
{"DIAL", "Dialog Topics"},
64+
{"QUST", "Quests"},
65+
{"IDLE", "Idle Animations"},
66+
{"PACK", "Packages"},
67+
{"CSTY", "Combat Style"},
68+
{"LSCR", "Loading Screens"},
69+
{"ANIO", "Animated Objects"},
70+
{"WATR", "Water Types"},
71+
{"EFSH", "Effect Shaders"},
72+
{"EXPL", "Explosions"},
73+
{"DEBR", "Debris"},
74+
{"IMGS", "Image Spaces"},
75+
{"IMAD", "Image Space Modifiers"},
76+
{"FLST", "Form Lists"},
77+
{"PERK", "Perks"},
78+
{"BPTD", "Body Part Data"},
79+
{"ADDN", "Addon Nodes"},
80+
{"AVIF", "Actor Value Info"},
81+
{"RADS", "Radiation Stages"},
82+
{"CAMS", "Camera Shots"},
83+
{"CPTH", "Camera Paths"},
84+
{"VTYP", "Voice Types"},
85+
{"IPCT", "Impacts"},
86+
{"IPDS", "Impact Data Sets"},
87+
{"ARMA", "Armor Addons"},
88+
{"ECZN", "Encounter Zones"},
89+
{"MESG", "Messages"},
90+
{"RGDL", "Ragdolls"},
91+
{"DOBJ", "Default Objects"},
92+
{"LGTM", "Lighting Templates"},
93+
{"MUSC", "Music"},
94+
{"IMOD", "Weapon Mods"},
95+
{"REPU", "Reputations"},
96+
{"RCPE", "Recipes"},
97+
{"RCCT", "Recipe Categories"},
98+
{"CHIP", "Casino Chips"},
99+
{"CSNO", "Casinos"},
100+
{"LSCT", "Load Screen Types"},
101+
{"MSET", "Media Sets"},
102+
{"ALOC", "Audio Location Controllers"},
103+
{"CHAL", "Challenges"},
104+
{"AMEF", "Ammo Effects"},
105+
{"CCRD", "Caravan Cards"},
106+
{"CMNY", "Caravan Money"},
107+
{"CDCK", "Caravan Decks"},
108+
{"DEHY", "Dehydration Stages"},
109+
{"HUNG", "Hunger Stages"},
110+
{"SLPD", "Sleep Deprivation Stages"},
111+
{"CELL", "Interior Cells"},
112+
{"WRLD", "Worldspaces"}
113+
};
114+
9115
public string RecordType { get; protected set; }
10116

11117
public TopGroup()
@@ -35,7 +141,7 @@ public override void ReadTypeDataXML(XElement element)
35141

36142
public override string ToString()
37143
{
38-
return RecordType;
144+
return tagToNameDictionary[RecordType];
39145
}
40146
}
41147
}

ESPSharp/Interfaces/IEditorID.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ESPSharp
8+
{
9+
public interface IEditorID
10+
{
11+
string EditorID { get; set; }
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ESPSharp
8+
{
9+
public interface IReferenceContainer
10+
{
11+
}
12+
}

0 commit comments

Comments
 (0)