Navigation Menu

Skip to content

Commit

Permalink
Updating StructConverter and DLLModGenerator for new SADX Mod Loader …
Browse files Browse the repository at this point in the history
…APIs.
  • Loading branch information
MainMemory committed Mar 10, 2015
1 parent 1d0d975 commit 6432d99
Show file tree
Hide file tree
Showing 6 changed files with 823 additions and 703 deletions.
51 changes: 6 additions & 45 deletions DLLModGenerator/IniData.cs
Expand Up @@ -56,7 +56,7 @@ public DllIniData()
}
}

public class DictionaryContainer<T> : IDictionary<string, T>
public class DictionaryContainer<T> : IEnumerable<KeyValuePair<string, T>>
{
[IniCollection(IniCollectionMode.IndexOnly)]
public Dictionary<string, T> Items { get; set; }
Expand All @@ -76,12 +76,6 @@ public bool ContainsKey(string key)
return Items.ContainsKey(key);
}

[IniIgnore]
public ICollection<string> Keys
{
get { return Items.Keys; }
}

public bool Remove(string key)
{
return Items.Remove(key);
Expand All @@ -92,12 +86,6 @@ public bool TryGetValue(string key, out T value)
return Items.TryGetValue(key, out value);
}

[IniIgnore]
public ICollection<T> Values
{
get { return Items.Values; }
}

public T this[string key]
{
get
Expand All @@ -121,41 +109,11 @@ public int Count
get { return Items.Count; }
}

bool ICollection<KeyValuePair<string, T>>.IsReadOnly
{
get { return false; }
}

public IEnumerator<KeyValuePair<string, T>> GetEnumerator()
{
return Items.GetEnumerator();
}

void ICollection<KeyValuePair<string, T>>.Add(KeyValuePair<string, T> item)
{
throw new NotImplementedException();
}

void ICollection<KeyValuePair<string, T>>.Clear()
{
throw new NotImplementedException();
}

bool ICollection<KeyValuePair<string, T>>.Contains(KeyValuePair<string, T> item)
{
throw new NotImplementedException();
}

void ICollection<KeyValuePair<string, T>>.CopyTo(KeyValuePair<string, T>[] array, int arrayIndex)
{
throw new NotImplementedException();
}

bool ICollection<KeyValuePair<string, T>>.Remove(KeyValuePair<string, T> item)
{
throw new NotImplementedException();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
Expand All @@ -178,12 +136,15 @@ public FileTypeHash(string data)
{
string[] split = data.Split('|');
Type = split[0];
Hash = split[1];
if (split.Length > 1)
Hash = split[1];
}

public override string ToString()
{
return Type + "|" + Hash;
if (Hash != null)
return Type + "|" + Hash;
return Type;
}
}

Expand Down
38 changes: 36 additions & 2 deletions DLLModGenerator/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 114 additions & 53 deletions DLLModGenerator/MainForm.cs
Expand Up @@ -122,66 +122,59 @@ private void button3_Click(object sender, EventArgs e)
listView1.EndUpdate();
}

private List<string> ExportCPP(TextWriter writer, bool SA2)
{
ModelFormat modelfmt = SA2 ? ModelFormat.Chunk : ModelFormat.BasicDX;
LandTableFormat landfmt = SA2 ? LandTableFormat.SA2 : LandTableFormat.SADX;
writer.WriteLine("// Generated by SA Tools DLL Mod Generator");
writer.WriteLine();
if (SA2)
writer.WriteLine("#include \"SA2ModLoader.h\"");
else
writer.WriteLine("#include \"SADXModLoader.h\"");
writer.WriteLine();
List<string> labels = new List<string>();
foreach (KeyValuePair<string, FileTypeHash> item in IniData.Files.Where((a, i) => listView1.CheckedIndices.Contains(i)))
switch (item.Value.Type)
{
case "landtable":
LandTable tbl = LandTable.LoadFromFile(item.Key);
writer.WriteLine(tbl.ToStructVariables(landfmt, new List<string>()));
labels.AddRange(tbl.GetLabels());
break;
case "model":
SonicRetro.SAModel.Object mdl = new ModelFile(item.Key).Model;
writer.WriteLine(mdl.ToStructVariables(modelfmt == ModelFormat.BasicDX, new List<string>()));
labels.AddRange(mdl.GetLabels());
break;
case "basicmodel":
case "chunkmodel":
mdl = new ModelFile(item.Key).Model;
writer.WriteLine(mdl.ToStructVariables(false, new List<string>()));
labels.AddRange(mdl.GetLabels());
break;
case "basicdxmodel":
mdl = new ModelFile(item.Key).Model;
writer.WriteLine(mdl.ToStructVariables(true, new List<string>()));
labels.AddRange(mdl.GetLabels());
break;
case "animation":
Animation ani = Animation.Load(item.Key);
writer.WriteLine(ani.ToStructVariables());
labels.Add(ani.Name);
break;
}
return labels;
}

private void button4_Click(object sender, EventArgs e)
{
using (SaveFileDialog fd = new SaveFileDialog() { DefaultExt = "cpp", Filter = "C++ source files|*.cpp", InitialDirectory = Environment.CurrentDirectory, RestoreDirectory = true })
if (fd.ShowDialog(this) == DialogResult.OK)
using (TextWriter writer = File.CreateText(fd.FileName))
{
bool SA2 = IniData.Game == Game.SA2B;
ModelFormat modelfmt = 0;
LandTableFormat landfmt = 0;
switch (IniData.Game)
{
case Game.SADX:
modelfmt = ModelFormat.BasicDX;
landfmt = LandTableFormat.SADX;
break;
case Game.SA2B:
modelfmt = ModelFormat.Chunk;
landfmt = LandTableFormat.SA2;
break;
}
writer.WriteLine("// Generated by SA Tools DLL Mod Generator");
writer.WriteLine();
if (SA2)
writer.WriteLine("#include \"SA2ModLoader.h\"");
else
writer.WriteLine("#include \"SADXModLoader.h\"");
writer.WriteLine();
List<string> labels = new List<string>();
int _i = 0;
foreach (KeyValuePair<string, FileTypeHash> item in IniData.Files)
if (listView1.CheckedIndices.Contains(_i++))
switch (item.Value.Type)
{
case "landtable":
LandTable tbl = LandTable.LoadFromFile(item.Key);
writer.WriteLine(tbl.ToStructVariables(landfmt, new List<string>()));
labels.AddRange(tbl.GetLabels());
break;
case "model":
SonicRetro.SAModel.Object mdl = new ModelFile(item.Key).Model;
writer.WriteLine(mdl.ToStructVariables(modelfmt == ModelFormat.BasicDX, new List<string>()));
labels.AddRange(mdl.GetLabels());
break;
case "basicmodel":
case "chunkmodel":
mdl = new ModelFile(item.Key).Model;
writer.WriteLine(mdl.ToStructVariables(false, new List<string>()));
labels.AddRange(mdl.GetLabels());
break;
case "basicdxmodel":
mdl = new ModelFile(item.Key).Model;
writer.WriteLine(mdl.ToStructVariables(true, new List<string>()));
labels.AddRange(mdl.GetLabels());
break;
case "animation":
Animation ani = Animation.Load(item.Key);
writer.WriteLine(ani.ToStructVariables());
labels.Add(ani.Name);
break;
}
List<string> labels = ExportCPP(writer, SA2);
writer.WriteLine("void __cdecl Init(const char *path, const HelperFunctions &helperFunctions)");
writer.WriteLine("{");
writer.WriteLine("\tHMODULE handle = GetModuleHandle(L\"{0}\");", IniData.Name);
Expand All @@ -195,6 +188,74 @@ private void button4_Click(object sender, EventArgs e)
writer.WriteLine("extern \"C\" __declspec(dllexport) const ModInfo {0}ModInfo = {{ ModLoaderVer, Init, NULL, 0, NULL, 0, NULL, 0, NULL, 0 }};", SA2 ? "SA2" : "SADX");
}
}

private void button5_Click(object sender, EventArgs e)
{
using (SaveFileDialog fd = new SaveFileDialog() { DefaultExt = "cpp", Filter = "C++ source files|*.cpp", InitialDirectory = Environment.CurrentDirectory, RestoreDirectory = true })
if (fd.ShowDialog(this) == DialogResult.OK)
using (TextWriter writer = File.CreateText(fd.FileName))
{
bool SA2 = IniData.Game == Game.SA2B;
List<string> labels = ExportCPP(writer, SA2);
writer.WriteLine("extern \"C\"");
writer.WriteLine("{");
writer.WriteLine();
writer.WriteLine("__declspec(dllexport) void __cdecl Init(const char *path, const HelperFunctions &helperFunctions)");
writer.WriteLine("{");
writer.WriteLine("\tHMODULE handle = GetModuleHandle(L\"{0}\");", IniData.Name);
List<string> exports = new List<string>(IniData.Items.Where(item => labels.Contains(item.Label)).Select(item => item.Export));
foreach (KeyValuePair<string, string> item in IniData.Exports.Where(item => exports.Contains(item.Key)))
writer.WriteLine("\t{0}{1} = ({0})GetProcAddress(handle, \"{1}\");", typemap[item.Value], item.Key);
foreach (DllItemInfo item in IniData.Items.Where(item => labels.Contains(item.Label)))
writer.WriteLine("\t{0} = &{1};", item.ToString(), item.Label);
writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("__declspec(dllexport) const ModInfo {0}ModInfo = {{ ModLoaderVer }};", SA2 ? "SA2" : "SADX");
writer.WriteLine();
writer.WriteLine("}");
}
}

private void button6_Click(object sender, EventArgs e)
{
using (SaveFileDialog fd = new SaveFileDialog() { DefaultExt = "ini", Filter = "INI files|*.ini", InitialDirectory = Environment.CurrentDirectory, RestoreDirectory = true })
if (fd.ShowDialog(this) == DialogResult.OK)
{
string dstfol = Path.GetDirectoryName(fd.FileName);
DllIniData output = new DllIniData();
output.Name = IniData.Name;
output.Game = IniData.Game;
output.Exports = IniData.Exports;
output.Files = new DictionaryContainer<FileTypeHash>();
List<string> labels = new List<string>();
foreach (KeyValuePair<string, FileTypeHash> item in IniData.Files.Where((a, i) => listView1.CheckedIndices.Contains(i)))
{
Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(dstfol, item.Key)));
File.Copy(item.Key, Path.Combine(dstfol, item.Key), true);
switch (item.Value.Type)
{
case "landtable":
LandTable tbl = LandTable.LoadFromFile(item.Key);
labels.AddRange(tbl.GetLabels());
break;
case "model":
case "basicmodel":
case "chunkmodel":
case "basicdxmodel":
SonicRetro.SAModel.Object mdl = new ModelFile(item.Key).Model;
labels.AddRange(mdl.GetLabels());
break;
case "animation":
Animation ani = Animation.Load(item.Key);
labels.Add(ani.Name);
break;
}
output.Files.Add(item.Key, new FileTypeHash(item.Value.Type, null));
}
output.Items = new List<DllItemInfo>(IniData.Items.Where(a => labels.Contains(a.Label)));
IniSerializer.Serialize(output, fd.FileName);
}
}
}

static class Extensions
Expand Down

0 comments on commit 6432d99

Please sign in to comment.