Skip to content

Commit

Permalink
Added wrapper for OpenCAGE
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Nov 23, 2020
1 parent 4adc406 commit 839a559
Show file tree
Hide file tree
Showing 27 changed files with 18,137 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Build/BEHAVIOUR_TREES/*

# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "BehaviourTreeTool/BehaviourTreeTool/SharedAssets"]
path = BehaviourTreeTool/BehaviourTreeTool/SharedAssets
url = https://github.com/OpenCAGE/SharedAssets
18 changes: 18 additions & 0 deletions BehaviourTreeTool/BehaviourTreeTool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Brainiac Designer", "Braini
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegendPlugin", "LegendPlugin\LegendPlugin.csproj", "{326CC795-9695-4B8E-9EB4-5C7EA28B0344}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviourTreeTool", "BehaviourTreeTool\BehaviourTreeTool.csproj", "{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -110,6 +112,22 @@ Global
{326CC795-9695-4B8E-9EB4-5C7EA28B0344}.Release|Win32.Build.0 = Release|Any CPU
{326CC795-9695-4B8E-9EB4-5C7EA28B0344}.Release|x64.ActiveCfg = Release|Any CPU
{326CC795-9695-4B8E-9EB4-5C7EA28B0344}.Release|x64.Build.0 = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|Win32.ActiveCfg = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|Win32.Build.0 = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|x64.ActiveCfg = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Debug|x64.Build.0 = Debug|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|Any CPU.Build.0 = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|Win32.ActiveCfg = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|Win32.Build.0 = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|x64.ActiveCfg = Release|Any CPU
{2683DDC8-E593-43D8-BA86-FDDD8FDD0801}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions BehaviourTreeTool/BehaviourTreeTool/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
184 changes: 184 additions & 0 deletions BehaviourTreeTool/BehaviourTreeTool/BML Scripts/AlienConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Alien Isolation (Binary XML converter)
// Written by WRS (xentax.com)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;

namespace BehaviourTreeTool
{
class AlienConverter
{
static string version_string = "0.03";

private void ShowInfo()
{
//Console.WriteLine("Usage:");
//Console.WriteLine("\tAlienBML.exe source_file <target_file>");
//Console.WriteLine("\t source_file A BML or XML filename");
//Console.WriteLine("\t target_file A BML or XML filename (optional)");
}

// basic extension check
static bool CheckExtension(string filename, string lower_ext = "bml")
{
int li = filename.LastIndexOf('.');

if (li != -1)
{
filename = filename.Substring(li + 1);
}

return filename.ToLower() == lower_ext;
}

// switch between extensions
static string ConvertFileName(string filename)
{
// strip extension
int li = filename.LastIndexOf('.');
string fn = (li != -1) ? filename.Substring(0, li) : filename;

if (CheckExtension(filename))
{
return fn + ".xml";
}
else
{
return fn + ".bml";
}
}

string filename_src, filename_dst;

bool ConvertFile(ref BML bml)
{
bool result = true;

//Console.WriteLine("Exporting to {0}...", filename_dst);

if (File.Exists(filename_dst))
{
//Console.WriteLine("Warning: destination file will be replaced");
File.Delete(filename_dst);
}

BinaryWriter bw = new BinaryWriter(File.OpenWrite(filename_dst));

if (CheckExtension(filename_dst, "xml") )
{
string data = "";
bml.ExportXML(ref data);

// writing raw data otherwise we get the string encoding header
bw.Write(Encoding.Default.GetBytes(data), 0, data.Length);
}
else if( CheckExtension(filename_dst) )
{
bml.ExportBML(bw);
}
else
{
result = false;
//Console.WriteLine("Unexpected destination file type \"{0}\"", filename_dst);
}

bw.Close();

return result;
}

bool ProcessFile()
{
FileStream strm;

try
{
strm = File.OpenRead(filename_src);
}
catch
{
//Console.WriteLine("Unable to open \"{0}\"", filename_src);
return false;
}

if (!strm.CanRead)
{
//Console.WriteLine("Unable to read \"{0}\"", filename_src);
return false;
}

BinaryReader br = new BinaryReader(strm);
BML bml = null;
bool valid = true;

if (CheckExtension(filename_src))
{
bml = new BML();
//Console.WriteLine("Reading as BML...");
valid = bml.ReadBML(br);

if( !valid )
{
//Console.WriteLine("Reading BML failed");
}
}
else if (CheckExtension(filename_src, "xml"))
{
bml = new BML();
//Console.WriteLine("Reading as XML...");
valid = bml.ReadXML(br);

if( !valid )
{
//Console.WriteLine("Reading XML failed");
}
}
else
{
valid = false;
// Console.WriteLine("Unexpected source file type \"{0}\"", filename_src);
}

strm.Close();

if( valid )
{
return ConvertFile(ref bml);
}

return valid;
}

public AlienConverter(string filenameSource, string filenameDestination)
{
filename_src = filenameSource;
filename_dst = filenameDestination;
}

public bool Run()
{
//Console.WriteLine("Alien Isolation BML Converter v{0}", version_string);
//Console.WriteLine("Written by WRS (xentax.com)");

if (filename_src == null)
{
ShowInfo();
return true;
}
else
{
if( filename_dst == null )
{
filename_dst = ConvertFileName(filename_src);
}

return ProcessFile();
}
}
}
}
Loading

0 comments on commit 839a559

Please sign in to comment.