Skip to content

Commit

Permalink
allow specify CustomSerializationFlags in settings form
Browse files Browse the repository at this point in the history
  • Loading branch information
atenfyr committed Jan 19, 2025
1 parent ba8f8b5 commit e2e03cb
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 17 deletions.
1 change: 1 addition & 0 deletions UAssetGUI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ private void LoadFileAtInternal(string filePath)
targetAsset = new UAsset(ParsingVersion);
targetAsset.FilePath = filePath;
targetAsset.Mappings = ParsingMappings;
targetAsset.CustomSerializationFlags = (CustomSerializationFlags)UAGConfig.Data.CustomSerializationFlags;
if (MapStructTypeOverrideForm.MapStructTypeOverride != null) targetAsset.MapStructTypeOverride = MapStructTypeOverrideForm.MapStructTypeOverride;

var strmRaw = targetAsset.PathToStream(filePath);
Expand Down
59 changes: 44 additions & 15 deletions UAssetGUI/SettingsForm.Designer.cs

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

45 changes: 44 additions & 1 deletion UAssetGUI/SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using UAssetAPI;

namespace UAssetGUI
{
Expand All @@ -16,6 +18,21 @@ public SettingsForm()
private void SettingsForm_Load(object sender, EventArgs e)
{
if (this.Owner is Form1) BaseForm = (Form1)this.Owner;

customSerializationFlagsBox.BeginUpdate();
customSerializationFlagsBox.Items.Clear();
List<CustomSerializationFlags> allFlags = Enum.GetValues(typeof(CustomSerializationFlags)).Cast<CustomSerializationFlags>().ToList();
int entryIdx = 0;
for (int i = 0; i < allFlags.Count; i++)
{
CustomSerializationFlags option = allFlags[i];
if (option == 0) continue;

customSerializationFlagsBox.Items.Add(option.ToString());
customSerializationFlagsBox.SetItemChecked(entryIdx++, (UAGConfig.Data.CustomSerializationFlags & (int)option) > 0);
}
customSerializationFlagsBox.EndUpdate();

themeComboBox.DataSource = Enum.GetValues(typeof(UAGTheme));
themeComboBox.SelectedIndex = (int)UAGPalette.GetCurrentTheme();
valuesOnScroll.Checked = UAGConfig.Data.ChangeValuesOnScroll;
Expand Down Expand Up @@ -156,5 +173,31 @@ private void numericUpDown1_ValueChanged(object sender, EventArgs e)
}
});
}

private void customSerializationFlagsBox_Click(object sender, EventArgs e)
{
// idea from https://stackoverflow.com/a/334672
for (int i = 0; i < customSerializationFlagsBox.Items.Count; i++)
{
if (customSerializationFlagsBox.GetItemRectangle(i).Contains(customSerializationFlagsBox.PointToClient(MousePosition)))
{
customSerializationFlagsBox.SetItemChecked(i, !customSerializationFlagsBox.GetItemChecked(i));
}
}

// update config
CustomSerializationFlags res = 0;
for (int i = 0; i < customSerializationFlagsBox.Items.Count; i++)
{
string item = customSerializationFlagsBox.Items[i] as string;
if (item == null) continue;
if (customSerializationFlagsBox.GetItemChecked(i))
{
res |= Enum.Parse<CustomSerializationFlags>(item);
}
}

UAGConfig.Data.CustomSerializationFlags = (int)res;
}
}
}
2 changes: 2 additions & 0 deletions UAssetGUI/UAGConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UAGConfigData
public bool EnablePrettyBytecode;
public int StartupWidth;
public int StartupHeight;
public int CustomSerializationFlags;

public UAGConfigData()
{
Expand All @@ -44,6 +45,7 @@ public UAGConfigData()
EnablePrettyBytecode = true;
StartupWidth = 1000;
StartupHeight = 700;
CustomSerializationFlags = 0;
}
}

Expand Down

0 comments on commit e2e03cb

Please sign in to comment.