Skip to content

Commit

Permalink
Fixed various issues with old XML/BML packing method
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Feb 19, 2022
1 parent 45b5221 commit 888af6b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 67 deletions.
10 changes: 5 additions & 5 deletions BehaviourTreeTool/BehaviourTreeTool/BehaviourPacker.Designer.cs

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

73 changes: 31 additions & 42 deletions BehaviourTreeTool/BehaviourTreeTool/BehaviourPacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Collections.Generic;

namespace BehaviourTreeTool
{
Expand All @@ -26,29 +27,27 @@ private void BehaviourPacker_Load(object sender, EventArgs e)
HeaderText.Font = FontManager.GetFont(1, 80);
HeaderText.Parent = HeaderImage;
Title4.Font = FontManager.GetFont(0, 20);
label1.Font = FontManager.GetFont(0, 20);
}

/* UNPACK */
private void unpackButton_Click(object sender, EventArgs e)
{
if (!Directory.Exists(SharedData.pathToBehaviourTrees)) Directory.CreateDirectory(SharedData.pathToBehaviourTrees);
if (!File.Exists(SharedData.pathToBehaviourTrees + "alien_all_search_variants.xml")) {
/* STARTING */
unpackButton.Enabled = false;
repackButton.Enabled = false;
resetTrees.Enabled = false;
Cursor.Current = Cursors.WaitCursor;

/* COPY _BINARY_BEHAVIOUR TO WORKING DIRECTORY */
//Convert BML to XML
File.Copy(SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\_DIRECTORY_CONTENTS.BML", SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.BML");

/* CONVERT _BINARY_BEHAVIOUR TO XML */
new AlienConverter(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.BML", SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml").Run();

/* EXTRACT XML TO SEPARATE FILES */
//Extract XML to separate files
string directoryContentsXML = File.ReadAllText(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml"); //Get contents from newly converted _DIRECTORY_CONTENTS
string fileHeader = "<?xml version='1.0' encoding='utf-8'?>\n<Behavior>"; //Premade file header
int count = 0;

foreach (string currentFile in Regex.Split(directoryContentsXML, "<File name="))
{
count += 1;
Expand All @@ -57,53 +56,45 @@ private void unpackButton_Click(object sender, EventArgs e)
string[] extractedContents = Regex.Split(currentFile, "<Behavior>"); //Split filename and contents
string[] extractedContentsMain = Regex.Split(extractedContents[1], "</File>"); //Split contents and footer
string[] fileContents = { fileHeader, extractedContentsMain[0] }; //Write preset header and newly grabbed contents
string fileName = "";
if (File.Exists(SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\gameismodded.txt") || //legacy
File.Exists(SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\packagingtool_hasmodded.ayz"))
{
fileName = extractedContents[0].Substring(1, extractedContents[0].Length - 9); //Grab filename
}
else
{
fileName = extractedContents[0].Substring(1, extractedContents[0].Length - 11); //Grab filename UNMODDED FILE
}
string fileName = extractedContents[0].Substring(1).Split(new string[] { ".bml" }, StringSplitOptions.None)[0]; //Grab filename

File.WriteAllLines(SharedData.pathToBehaviourTrees + fileName + ".xml", fileContents); //Write new file
}
}

/* DELETE EXCESS FILES */
File.Delete(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.BML");
File.Delete(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml");

/* DONE */
Cursor.Current = Cursors.Default;
unpackButton.Enabled = true;
repackButton.Enabled = true;
resetTrees.Enabled = true;
}

/* OPEN BRAINIAC */
//Open Brainiac Designer
ProcessStartInfo brainiacProcess = new ProcessStartInfo();
brainiacProcess.WorkingDirectory = Environment.CurrentDirectory;
brainiacProcess.FileName = Environment.CurrentDirectory + "/Brainiac Designer.exe";
Process myProcess = Process.Start(brainiacProcess);
Process.Start(brainiacProcess);
}

/* REPACK */
private void repackButton_Click(object sender, EventArgs e)
{
if (File.Exists(SharedData.pathToBehaviourTrees + "alien_all_search_variants.xml"))
if (!Directory.Exists(SharedData.pathToBehaviourTrees)) Directory.CreateDirectory(SharedData.pathToBehaviourTrees);
if (!File.Exists(SharedData.pathToBehaviourTrees + "alien_all_search_variants.xml"))
{
MessageBox.Show("No modifications have been made! Nothing to import.");
}
else
{
/* STARTING */
unpackButton.Enabled = false;
repackButton.Enabled = false;
resetTrees.Enabled = false;
Cursor.Current = Cursors.WaitCursor;

/* WRITE NEW _DIRECTORY_CONTENTS XML AND DELETE FILES */
//Create new XML to write
string compiledBinaryBehaviourContents = "<?xml version=\"1.0\" encoding=\"utf-8\"?><DIR>"; //Start file

DirectoryInfo workingDirectoryInfo = new DirectoryInfo(SharedData.pathToBehaviourTrees); //Get all files in directory
foreach (FileInfo currentFile in workingDirectoryInfo.GetFiles())
{
Expand All @@ -114,54 +105,52 @@ private void repackButton_Click(object sender, EventArgs e)

compiledBinaryBehaviourContents += customFileHeader + fileContents.Substring(38) + customFileFooter; //Add to file string
}

compiledBinaryBehaviourContents += "</DIR>"; //Finish off file string

string[] compiledContentsAsArray = { compiledBinaryBehaviourContents };
File.WriteAllLines(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml", compiledContentsAsArray); //Write new file

/* CONVERT _BINARY_BEHAVIOUR TO BML */
//Write and convert to BML
File.WriteAllText(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml", compiledBinaryBehaviourContents);
new AlienConverter(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml", SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.bml").Run();

/* COPY _BINARY_BEHAVIOUR TO GAME AND DELETE FILES */
File.Delete(SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\_DIRECTORY_CONTENTS.BML");
File.Copy(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.bml", SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\_DIRECTORY_CONTENTS.BML");
string[] moddedGameText = { "DO NOT DELETE THIS FILE" };
File.WriteAllLines(SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\packagingtool_hasmodded.ayz", moddedGameText); //Write modded game text
File.Delete(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.bml");
File.Delete(SharedData.pathToBehaviourTrees + "_DIRECTORY_CONTENTS.xml");

/* DONE */
Cursor.Current = Cursors.Default;
MessageBox.Show("Modifications have been imported.");
unpackButton.Enabled = true;
repackButton.Enabled = true;
resetTrees.Enabled = true;
}
else
{
MessageBox.Show("No modifications have been made! Nothing to import.");

MessageBox.Show("Modifications have been imported.");
}
}

/* RESET */
private void resetTrees_Click(object sender, EventArgs e)
{
/* STARTING */
unpackButton.Enabled = false;
repackButton.Enabled = false;
resetTrees.Enabled = false;
Cursor.Current = Cursors.WaitCursor;

/* RESET FILE */
//Kill Brainiac
List<Process> allProcesses = new List<Process>(Process.GetProcessesByName("Brainiac Designer"));
for (int i = 0; i < allProcesses.Count; i++) allProcesses[i].Kill();

//Reset files
File.WriteAllBytes(SharedData.pathToAI + @"\DATA\BINARY_BEHAVIOR\_DIRECTORY_CONTENTS.BML", Properties.Resources._DIRECTORY_CONTENTS);
if (Directory.Exists(SharedData.pathToBehaviourTrees))
{
string[] trees = Directory.GetFiles(SharedData.pathToBehaviourTrees, "*.xml", SearchOption.TopDirectoryOnly);
for (int i = 0; i < trees.Length; i++) File.Delete(trees[i]);
}

/* DONE */
Cursor.Current = Cursors.Default;
MessageBox.Show("Changes reset to vanilla.\nIf you have the editor open, close it and re-open through this window.", "Please relaunch the editor if open!", MessageBoxButtons.OK, MessageBoxIcon.Information);
unpackButton.Enabled = true;
repackButton.Enabled = true;
resetTrees.Enabled = true;

MessageBox.Show("Behaviour trees have been reset to defaults!", "Reset complete.", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

//Close
Expand Down
4 changes: 3 additions & 1 deletion BehaviourTreeTool/BehaviourTreeTool/BehaviourTreeTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down
2 changes: 1 addition & 1 deletion BehaviourTreeTool/LegendPlugin/Action/ActionAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public string AssertInfo
set { _AssertInfo = value; }
}

public ActionAssert() : base("Asset", "ASSERT AN ERROR - USED FOR DEBUGGING.")
public ActionAssert() : base("Assert", "ASSERT AN ERROR - USED FOR DEBUGGING.")

{
}
Expand Down
16 changes: 7 additions & 9 deletions BehaviourTreeTool/LegendPlugin/Sequence/SequenceLinear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,22 @@ public class SequenceLinear : Sequence
{
//All parameters added

protected ChildStateType _stateType;
//private string _Name = "";
protected ChildStateType _childStateType;
private string _Name = "";

[DesignerEnum("Child state type", "ChildStateType", "CategoryBasic", DesignerProperty.DisplayMode.Parameter, 0, DesignerProperty.DesignerFlags.NoFlags, null)]
public ChildStateType stateType
public ChildStateType ChildStateType
{
get { return _stateType; }
set { _stateType = value; }
get { return _childStateType; }
set { _childStateType = value; }
}

/*
[DesignerString("Name", "Name", "CategoryBasic", DesignerProperty.DisplayMode.Parameter, 0, DesignerProperty.DesignerFlags.NoFlags)]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
*/

public SequenceLinear() : base("Linear", "A LINEAR SEQUENCE.")

Expand All @@ -67,8 +65,8 @@ protected override void CloneProperties(Node newnode)
base.CloneProperties(newnode);

SequenceLinear cond = (SequenceLinear)newnode;
cond._stateType = _stateType;
//cond._Name = _Name;
cond._childStateType = _childStateType;
cond._Name = _Name;
}
}
}
16 changes: 7 additions & 9 deletions BehaviourTreeTool/LegendPlugin/Sequence/SequenceStateless.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,22 @@ public class SequenceStateless : Sequence
{
//All parameters added

protected ChildStateType _stateType;
//private string _Name = "";
protected ChildStateType _childStateType;
private string _Name = "";

[DesignerEnum("Child state type", "ChildStateType", "CategoryBasic", DesignerProperty.DisplayMode.Parameter, 0, DesignerProperty.DesignerFlags.NoFlags, null)]
public ChildStateType stateType
public ChildStateType ChildStateType
{
get { return _stateType; }
set { _stateType = value; }
get { return _childStateType; }
set { _childStateType = value; }
}

/*
[DesignerString("Name", "Name", "CategoryBasic", DesignerProperty.DisplayMode.Parameter, 0, DesignerProperty.DesignerFlags.NoFlags)]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
*/

public SequenceStateless() : base("Stateless", "A SEQUENCE THAT IS STATELESS.")

Expand All @@ -67,8 +65,8 @@ protected override void CloneProperties(Node newnode)
base.CloneProperties(newnode);

SequenceStateless cond = (SequenceStateless)newnode;
cond._stateType = _stateType;
//cond._Name = _Name;
cond._childStateType = _childStateType;
cond._Name = _Name;
}
}
}
Binary file modified Build/BehaviourTreeTool.exe
Binary file not shown.
Binary file modified Build/plugins/LegendPlugin.dll
Binary file not shown.

0 comments on commit 888af6b

Please sign in to comment.