Skip to content

Commit

Permalink
some cleanup, add more spline import controls
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamsyntax committed Aug 11, 2024
1 parent 2b6494f commit 22b175e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 75 deletions.
8 changes: 4 additions & 4 deletions HeroesPowerPlant/HeroesPowerPlant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>2024.07.18</ApplicationVersion>
<ProductVersion>2024.07.18</ProductVersion>
<ApplicationVersion>2024.08.10</ApplicationVersion>
<ProductVersion>2024.08.10</ProductVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<AssemblyTitle>HeroesPowerPlant</AssemblyTitle>
<Company>Heroes Hacking Central</Company>
<Product>Heroes Power Plant</Product>
<Copyright>Copyright © 2018-2024 igorseabra4 + friends</Copyright>
<AssemblyVersion>2024.07.18</AssemblyVersion>
<FileVersion>2024.07.18</FileVersion>
<AssemblyVersion>2024.08.10</AssemblyVersion>
<FileVersion>2024.08.10</FileVersion>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseWindowsForms>true</UseWindowsForms>
Expand Down
1 change: 0 additions & 1 deletion HeroesPowerPlant/LevelEditor/LevelEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ private void ShadowLevelMenuItemCollisionEditor_Click(object sender, EventArgs e
{
shadowCollisionEditor.Show();
shadowCollisionEditor.Focus();

}

private void ShadowLevelMenuItemSplineEditor_Click(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion HeroesPowerPlant/MainForm/MainForm.Designer.cs

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

2 changes: 1 addition & 1 deletion HeroesPowerPlant/Resources/hpp_version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "2024.07.18",
"version": "2024.08.10",
"versionName": "To stay on the current version, disable:\nOptions -> Check For Updates on Startup"
}
19 changes: 12 additions & 7 deletions HeroesPowerPlant/ShadowSplineEditor/ShadowSpline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ public class ShadowSpline : AbstractSpline
public int SettingInt { get; set; }
public string Name { get; set; }

// workaround to force Collection editor, should not be an array ideally
public ShadowSplineSec5Bytes[] UnknownSec5Bytes { get; set; }
public ShadowSplinePOF0 pof0 { get; set; }

public ShadowSplineVertex[] Vertices { get; set; }

public ShadowSpline()
{
Vertices = new ShadowSplineVertex[0];
UnknownSec5Bytes = new ShadowSplineSec5Bytes[0];
pof0 = new ShadowSplinePOF0();
Name = "NewSpline";
}

Expand All @@ -45,7 +44,7 @@ public ShadowSpline GetCopy()
Setting4 = Setting4,
SettingInt = SettingInt,
Name = Name,
UnknownSec5Bytes = JsonConvert.DeserializeObject<ShadowSplineSec5Bytes[]>(JsonConvert.SerializeObject(UnknownSec5Bytes)),
pof0 = JsonConvert.DeserializeObject<ShadowSplinePOF0>(JsonConvert.SerializeObject(pof0)),
Vertices = JsonConvert.DeserializeObject<ShadowSplineVertex[]>(JsonConvert.SerializeObject(Vertices))
};
}
Expand All @@ -59,7 +58,7 @@ public void SetRenderStuff(SharpRenderer renderer)
CreateMesh(renderer, vertices.ToArray());
}

public static ShadowSpline FromFile(string FileName)
public static ShadowSpline FromFile(string FileName, int splineId, string splinePrefix)
{
string[] SplineFile = File.ReadAllLines(FileName);
ShadowSpline Temp = new ShadowSpline();
Expand All @@ -70,10 +69,16 @@ public static ShadowSpline FromFile(string FileName)
if (j.StartsWith("v"))
{
string[] a = Regex.Replace(j, @"\s+", " ").Split();
Points.Add(new ShadowSplineVertex() { Position = new Vector3(Convert.ToSingle(a[1]), Convert.ToSingle(a[2]), Convert.ToSingle(a[3])), RotationY = Convert.ToUInt16(a[4]) * (360.0f / 65535), RotationX = Convert.ToUInt16(a[5]) * (360.0f / 65535) });//ReadWriteCommon.BAMStoRadians(Convert.ToSingle(a[5])) * 180f * MathUtil.Pi });
Points.Add(new ShadowSplineVertex() {
//TODO: Figure out better conversion
AngularAttachmentToleranceInt = 4, Position = new Vector3(Convert.ToSingle(a[1]), Convert.ToSingle(a[2]), Convert.ToSingle(a[3])), RotationY = Convert.ToUInt16(a[4]) * (360.0f / 65535), RotationX = Convert.ToUInt16(a[5]) * (360.0f / 65535)
});//ReadWriteCommon.BAMStoRadians(Convert.ToSingle(a[5])) * 180f * MathUtil.Pi });
}
}

Points.Last().AngularAttachmentToleranceInt = 0; // last point needs AAT of 0
Temp.Name = splinePrefix + splineId;
Temp.SplineType = 2;
Temp.SettingInt = splineId;
Temp.Vertices = Points.ToArray();
Temp.SetRenderStuff(Program.MainForm.renderer);
return Temp;
Expand Down
56 changes: 23 additions & 33 deletions HeroesPowerPlant/ShadowSplineEditor/ShadowSplineEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private static List<ShadowSpline> ReadShadowSplineFile(string fileName, Endianne
if (splineReader == null)
return new List<ShadowSpline>();

try
{
//try
//{
List<ShadowSpline> splineList = new List<ShadowSpline>();

splineReader.BaseStream.Position = 0x4;
Expand Down Expand Up @@ -139,30 +139,32 @@ private static List<ShadowSpline> ReadShadowSplineFile(string fileName, Endianne
if (byte0 >= 0x80)
{
byte byte1 = splineReader.ReadByte();
splineList[i].UnknownSec5Bytes = new ShadowSplineSec5Bytes[1] { new ShadowSplineSec5Bytes { slot1 = byte0, slot2 = byte1, noSlot2 = false } };
splineList[i].pof0 = new ShadowSplinePOF0 { slot1 = byte0, slot2 = byte1, noSlot2 = false };
}
else
splineList[i].UnknownSec5Bytes = new ShadowSplineSec5Bytes[1] { new ShadowSplineSec5Bytes { slot1 = byte0, noSlot2 = true } };

{
splineList[i].pof0 = new ShadowSplinePOF0 { slot1 = byte0, noSlot2 = true };
}
splineReader.ReadByte();
}

splineReader.Close();

return splineList;
}
catch (Exception ex)
//}
/* catch (Exception ex)
{
if (endianness == Endianness.Little)
{
return ReadShadowSplineFile(fileName, Endianness.Big);
}
else
{
MessageBox.Show("Unable to read spline file: " + ex.Message);
//MessageBox.Show("Unable to read spline file: " + ex.Message);
throw ex;
//throw new Exception("Unable to read spline file: " + ex.Message);
}
}
}*/
}

return new List<ShadowSpline>();
Expand All @@ -188,11 +190,13 @@ public IEnumerable<byte> ShadowSplinesToByteArray(string shadowFolderNamePrefix)
for (int i = 0; i < 10; i++)
bytes.Add(0);
}
while (bytes.Count % 0x20 != 0)
bytes.Add(0);

foreach (ShadowSpline s in Splines)
bytes.AddRange(BitConverter.GetBytes(0));

while (bytes.Count % 0x10 != 0)
while (bytes.Count % 0x20 != 0)
bytes.Add(0);

List<int> offsets = new List<int>();
Expand Down Expand Up @@ -233,29 +237,12 @@ public IEnumerable<byte> ShadowSplinesToByteArray(string shadowFolderNamePrefix)
bytes.Add(0);

offsets.Add(bytes.Count - 0x20);
int section5startOffset = bytes.Count - 0x20;
int pof0startOffset = bytes.Count - 0x20;

offsetLocations.Sort();
var pof0 = POF0.GenerateRawPOF0(offsetLocations);
bytes.AddRange(pof0);

/*
for (int i = 1; i < Splines.Count; i++)
bytes.Add(0x41);
for (int i = 0; i < Splines.Count; i++)
{
bytes.Add(Splines[i].UnknownSec5Bytes[0].slot1);
if (!Splines[i].UnknownSec5Bytes[0].noSlot2)
bytes.Add(Splines[i].UnknownSec5Bytes[0].slot2);
bytes.Add(0x49);
}
while (bytes.Count % 0x4 != 0)
bytes.Add(0);
*/

int section5length = bytes.Count - section5startOffset - 0x20;
int pof0Length = pof0.Length;

for (int i = 0; i < 8; i++)
Expand All @@ -277,7 +264,7 @@ public IEnumerable<byte> ShadowSplinesToByteArray(string shadowFolderNamePrefix)
bytes[2] = aux[1];
bytes[3] = aux[0];

aux = BitConverter.GetBytes(section5startOffset);
aux = BitConverter.GetBytes(pof0startOffset);

bytes[4] = aux[3];
bytes[5] = aux[2];
Expand Down Expand Up @@ -317,15 +304,18 @@ public void Add()
UnsavedChanges = true;
}

public void Add(string[] fileNames)
public void Add(string[] fileNames, string splinePrefix, int splineSuffixNumber)
{
foreach (string s in fileNames)
Add(s);
{
Add(s, splineSuffixNumber, splinePrefix);
splineSuffixNumber++;
}
}

public void Add(string objFile)
public void Add(string objFile, int splineId, string splinePrefix)
{
Splines.Add(ShadowSpline.FromFile(objFile));
Splines.Add(ShadowSpline.FromFile(objFile, splineId, splinePrefix));
Splines.Last().SetRenderStuff(Program.MainForm.renderer);
UnsavedChanges = true;
}
Expand Down
34 changes: 29 additions & 5 deletions HeroesPowerPlant/ShadowSplineEditor/ShadowSplineMenu.Designer.cs

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

25 changes: 17 additions & 8 deletions HeroesPowerPlant/ShadowSplineEditor/ShadowSplineMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ private void buttonAdd_Click(object sender, EventArgs e) {
}

private void buttonImport_Click(object sender, EventArgs e) {
VistaOpenFileDialog openSpline = new VistaOpenFileDialog() {
Multiselect = true,
Filter = ".obj files|*.obj"
};
if (openSpline.ShowDialog() == DialogResult.OK) {
SplineEditor.Add(openSpline.FileNames);
UpdateSplineList();
listBoxSplines.SelectedIndex = listBoxSplines.Items.Count - 1;
try
{
int suffix = int.Parse(textBox_splineSuffixNumber.Text);
VistaOpenFileDialog openSpline = new VistaOpenFileDialog()
{
Multiselect = true,
Filter = ".obj files|*.obj"
};
if (openSpline.ShowDialog() == DialogResult.OK)
{
SplineEditor.Add(openSpline.FileNames, textBox_splineNamePrefix.Text, suffix);
UpdateSplineList();
listBoxSplines.SelectedIndex = listBoxSplines.Items.Count - 1;
}
} catch(Exception ex)
{
MessageBox.Show("Double check your spline suffix number.\n\n" + ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace HeroesPowerPlant.ShadowSplineEditor
{
public class ShadowSplineSec5Bytes
{
public byte slot1 { get; set; }
public byte slot2 { get; set; }
public bool noSlot2 { get; set; }

public override string ToString()
{
return $"S1: {slot1} | S2: {slot2} | noS2: {noSlot2}";
}
}
namespace HeroesPowerPlant.ShadowSplineEditor
{
public class ShadowSplinePOF0
{
public byte slot1 { get; set; }
public byte slot2 { get; set; }
public bool noSlot2 { get; set; }

public override string ToString()
{
return $"S1: {slot1} | S2: {slot2} | noS2: {noSlot2}";
}
}
}
4 changes: 2 additions & 2 deletions HeroesPowerPlant/Shared/IO/Config/HPPVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class HPPVersion
{
public string version = "2024.07.18";
public string versionName = "2024.07.18";
public string version = "2024.08.10";
public string versionName = "2024.08.10";
}
}

0 comments on commit 22b175e

Please sign in to comment.