diff --git a/OpenKh.Command.AnbMaker/OpenKh.Command.AnbMaker.csproj b/OpenKh.Command.AnbMaker/OpenKh.Command.AnbMaker.csproj index ea90b4b38..90a441327 100644 --- a/OpenKh.Command.AnbMaker/OpenKh.Command.AnbMaker.csproj +++ b/OpenKh.Command.AnbMaker/OpenKh.Command.AnbMaker.csproj @@ -12,7 +12,7 @@ - + diff --git a/OpenKh.Command.Bdxio/Antlr4/.gitignore b/OpenKh.Command.Bdxio/Antlr4/.gitignore deleted file mode 100644 index 6161d9e8a..000000000 --- a/OpenKh.Command.Bdxio/Antlr4/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/.antlr -/.vscode -/BdxScript.interp -/BdxScript.tokens -/BdxScriptLexer.interp -/BdxScriptLexer.tokens -/test.bdxa diff --git a/OpenKh.Command.Bdxio/Commands/DecodeCommand.cs b/OpenKh.Command.Bdxio/Commands/DecodeCommand.cs index 2a3217590..84731e7d8 100644 --- a/OpenKh.Command.Bdxio/Commands/DecodeCommand.cs +++ b/OpenKh.Command.Bdxio/Commands/DecodeCommand.cs @@ -1,6 +1,6 @@ using McMaster.Extensions.CommandLineUtils; using NLog; -using OpenKh.Command.Bdxio.Utils; +using OpenKh.Kh2.Bdx.Utils; using System.ComponentModel.DataAnnotations; namespace OpenKh.Command.Bdxio.Commands diff --git a/OpenKh.Command.Bdxio/Commands/EncodeCommand.cs b/OpenKh.Command.Bdxio/Commands/EncodeCommand.cs index 40ee6230e..7a92963cf 100644 --- a/OpenKh.Command.Bdxio/Commands/EncodeCommand.cs +++ b/OpenKh.Command.Bdxio/Commands/EncodeCommand.cs @@ -1,7 +1,7 @@ using McMaster.Extensions.CommandLineUtils; using NLog; -using OpenKh.Command.Bdxio.Models; -using OpenKh.Command.Bdxio.Utils; +using OpenKh.Kh2.Bdx.Models; +using OpenKh.Kh2.Bdx.Utils; using System.ComponentModel.DataAnnotations; namespace OpenKh.Command.Bdxio.Commands diff --git a/OpenKh.Command.Bdxio/OpenKh.Command.Bdxio.csproj b/OpenKh.Command.Bdxio/OpenKh.Command.Bdxio.csproj index f517bf759..6e7675814 100644 --- a/OpenKh.Command.Bdxio/OpenKh.Command.Bdxio.csproj +++ b/OpenKh.Command.Bdxio/OpenKh.Command.Bdxio.csproj @@ -9,12 +9,13 @@ - + + diff --git a/OpenKh.Command.IdxImg/EpicGamesAssets.cs b/OpenKh.Command.IdxImg/EpicGamesAssets.cs index 642fbb8ff..88ed18b8f 100644 --- a/OpenKh.Command.IdxImg/EpicGamesAssets.cs +++ b/OpenKh.Command.IdxImg/EpicGamesAssets.cs @@ -130,6 +130,8 @@ private class BuildCommand protected int OnExecute(CommandLineApplication app) { + List _gameMap = new List() { "kh1", "kh2", "Recom", "bbs", "kh3d" }; + var enabled = File.ReadAllLines(ModsFile); if (Directory.Exists(OutputFolder)) @@ -141,9 +143,9 @@ protected int OnExecute(CommandLineApplication app) foreach (var mod_name in enabled.AsEnumerable().Reverse()) { var mod_folder = Path.Combine(ModsFolder, mod_name); - var metadata = File.OpenRead(Path.Combine(mod_folder, "mod.yml")).Using(Metadata.Read); + var metadata = Metadata.Read(Path.Combine(mod_folder, "mod.yml")); Console.WriteLine($"Patching {mod_name}"); - patcher.Patch(DataFolder, OutputFolder, metadata, mod_folder, platform: 2, packageMap: map, LaunchGame: GameId); + patcher.Patch(DataFolder, OutputFolder, metadata, mod_folder, targetPlatform: 1, packageMap: map, targetGame: _gameMap.IndexOf(GameId)); } using (var packageMapWriter = new StreamWriter(Path.Combine(OutputFolder, "patch-package-map.txt"))) diff --git a/OpenKh.Command.MapGen/OpenKh.Command.MapGen.csproj b/OpenKh.Command.MapGen/OpenKh.Command.MapGen.csproj index 21f7c9247..85396ee7a 100644 --- a/OpenKh.Command.MapGen/OpenKh.Command.MapGen.csproj +++ b/OpenKh.Command.MapGen/OpenKh.Command.MapGen.csproj @@ -14,7 +14,7 @@ - + diff --git a/OpenKh.Command.Bdxio/Antlr4/BdxScript.g4 b/OpenKh.Kh2/Bdx/Antlr/BdxScript.g4 similarity index 95% rename from OpenKh.Command.Bdxio/Antlr4/BdxScript.g4 rename to OpenKh.Kh2/Bdx/Antlr/BdxScript.g4 index de02fc9d4..8241372bd 100644 --- a/OpenKh.Command.Bdxio/Antlr4/BdxScript.g4 +++ b/OpenKh.Kh2/Bdx/Antlr/BdxScript.g4 @@ -1,49 +1,49 @@ -grammar BdxScript; - -prog: NL* (statement NL*)* EOF; -statement: - section - | equ - | label ':' NL - | label ':' order - | order; - -label: name = id; - -equ: name = id 'equ' numberdata; - -order: db | resb | dw | resw | instruction | include; - -dw: 'dw' worddata (',' worddata)* NL; -db: 'db' bytedata (',' bytedata)* NL; -resb: 'resb' (numberdata | id) NL; -resw: 'resw' (numberdata | id) NL; - -instruction: id (arg (',' arg)*)? NL; - -arg: (numberdata | id); -offset: 'offset' id; -bytedata: numberdata | id | StringData; -worddata: numberdata | id; -numberdata: - decimalnumber = DEC - | '0x' hexnumber = (DEC | HEX) - | floatnumber = FLOATNUM; -hexbody: DEC | HEX; -id: DEC | HEX | ID; -include: '%include' FileName NL; -section: 'section' section_id NL; -section_id: '.text' | '.bss'; - -StringData: '\'' ~[']* '\''; -DEC: [-+]? [0-9]+; -HEX: [0-9a-fA-F]+; -FLOATNUM: - [-+]? ([0-9]* '.' [0-9]+) - | ([0-9]+ [eE] [-+]? [0-9]+); -ID: [a-zA-Z_][a-zA-Z0-9_]* ('.' [a-zA-Z0-9_]+)*; -WS: [ \t] -> skip; -NL: '\r'? '\n' | '\r'; -FileName: '"' ~["]* '"'; - -LINE_COMMENT: ';' ~[\r\n]* -> skip; +grammar BdxScript; + +prog: NL* (statement NL*)* EOF; +statement: + section + | equ + | label ':' NL + | label ':' order + | order; + +label: name = id; + +equ: name = id 'equ' numberdata; + +order: db | resb | dw | resw | instruction | include; + +dw: 'dw' worddata (',' worddata)* NL; +db: 'db' bytedata (',' bytedata)* NL; +resb: 'resb' (numberdata | id) NL; +resw: 'resw' (numberdata | id) NL; + +instruction: id (arg (',' arg)*)? NL; + +arg: (numberdata | id); +offset: 'offset' id; +bytedata: numberdata | id | StringData; +worddata: numberdata | id; +numberdata: + decimalnumber = DEC + | '0x' hexnumber = (DEC | HEX) + | floatnumber = FLOATNUM; +hexbody: DEC | HEX; +id: DEC | HEX | ID; +include: '%include' FileName NL; +section: 'section' section_id NL; +section_id: '.text' | '.bss'; + +StringData: '\'' ~[']* '\''; +DEC: [-+]? [0-9]+; +HEX: [0-9a-fA-F]+; +FLOATNUM: + [-+]? ([0-9]* '.' [0-9]+) + | ([0-9]+ [eE] [-+]? [0-9]+); +ID: [a-zA-Z_][a-zA-Z0-9_]* ('.' [a-zA-Z0-9_]+)*; +WS: [ \t] -> skip; +NL: '\r'? '\n' | '\r'; +FileName: '"' ~["]* '"'; + +LINE_COMMENT: ';' ~[\r\n]* -> skip; diff --git a/OpenKh.Command.Bdxio/Antlr4/BdxScriptLexer.cs b/OpenKh.Kh2/Bdx/Antlr/BdxScriptLexer.cs similarity index 96% rename from OpenKh.Command.Bdxio/Antlr4/BdxScriptLexer.cs rename to OpenKh.Kh2/Bdx/Antlr/BdxScriptLexer.cs index aebe4593b..f242237c9 100644 --- a/OpenKh.Command.Bdxio/Antlr4/BdxScriptLexer.cs +++ b/OpenKh.Kh2/Bdx/Antlr/BdxScriptLexer.cs @@ -1,177 +1,177 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.11.1 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from BdxScript.g4 by ANTLR 4.11.1 - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 -// Ambiguous reference in cref attribute -#pragma warning disable 419 - -using System; -using System.IO; -using System.Text; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using DFA = Antlr4.Runtime.Dfa.DFA; - -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.11.1")] -[System.CLSCompliant(false)] -public partial class BdxScriptLexer : Lexer { - protected static DFA[] decisionToDFA; - protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); - public const int - T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, - T__9=10, T__10=11, T__11=12, T__12=13, StringData=14, DEC=15, HEX=16, - FLOATNUM=17, ID=18, WS=19, NL=20, FileName=21, LINE_COMMENT=22; - public static string[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static string[] modeNames = { - "DEFAULT_MODE" - }; - - public static readonly string[] ruleNames = { - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "T__9", "T__10", "T__11", "T__12", "StringData", "DEC", "HEX", "FLOATNUM", - "ID", "WS", "NL", "FileName", "LINE_COMMENT" - }; - - - public BdxScriptLexer(ICharStream input) - : this(input, Console.Out, Console.Error) { } - - public BdxScriptLexer(ICharStream input, TextWriter output, TextWriter errorOutput) - : base(input, output, errorOutput) - { - Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); - } - - private static readonly string[] _LiteralNames = { - null, "':'", "'equ'", "'dw'", "','", "'db'", "'resb'", "'resw'", "'offset'", - "'0x'", "'%include'", "'section'", "'.text'", "'.bss'" - }; - private static readonly string[] _SymbolicNames = { - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, "StringData", "DEC", "HEX", "FLOATNUM", "ID", "WS", "NL", - "FileName", "LINE_COMMENT" - }; - public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); - - [NotNull] - public override IVocabulary Vocabulary - { - get - { - return DefaultVocabulary; - } - } - - public override string GrammarFileName { get { return "BdxScript.g4"; } } - - public override string[] RuleNames { get { return ruleNames; } } - - public override string[] ChannelNames { get { return channelNames; } } - - public override string[] ModeNames { get { return modeNames; } } - - public override int[] SerializedAtn { get { return _serializedATN; } } - - static BdxScriptLexer() { - decisionToDFA = new DFA[_ATN.NumberOfDecisions]; - for (int i = 0; i < _ATN.NumberOfDecisions; i++) { - decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); - } - } - private static int[] _serializedATN = { - 4,0,22,207,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, - 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, - 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, - 7,21,1,0,1,0,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,3,1,3,1,4,1,4,1,4,1,5,1,5,1, - 5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8, - 1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,10,1,10, - 1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,13,1,13, - 5,13,110,8,13,10,13,12,13,113,9,13,1,13,1,13,1,14,3,14,118,8,14,1,14,4, - 14,121,8,14,11,14,12,14,122,1,15,4,15,126,8,15,11,15,12,15,127,1,16,3, - 16,131,8,16,1,16,5,16,134,8,16,10,16,12,16,137,9,16,1,16,1,16,4,16,141, - 8,16,11,16,12,16,142,1,16,4,16,146,8,16,11,16,12,16,147,1,16,1,16,3,16, - 152,8,16,1,16,4,16,155,8,16,11,16,12,16,156,3,16,159,8,16,1,17,1,17,5, - 17,163,8,17,10,17,12,17,166,9,17,1,17,1,17,4,17,170,8,17,11,17,12,17,171, - 5,17,174,8,17,10,17,12,17,177,9,17,1,18,1,18,1,18,1,18,1,19,3,19,184,8, - 19,1,19,1,19,3,19,188,8,19,1,20,1,20,5,20,192,8,20,10,20,12,20,195,9,20, - 1,20,1,20,1,21,1,21,5,21,201,8,21,10,21,12,21,204,9,21,1,21,1,21,0,0,22, - 1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14, - 29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,1,0,10,1,0,39,39,2,0,43, - 43,45,45,1,0,48,57,3,0,48,57,65,70,97,102,2,0,69,69,101,101,3,0,65,90, - 95,95,97,122,4,0,48,57,65,90,95,95,97,122,2,0,9,9,32,32,1,0,34,34,2,0, - 10,10,13,13,224,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1, - 0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0, - 0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31, - 1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0, - 0,0,43,1,0,0,0,1,45,1,0,0,0,3,47,1,0,0,0,5,51,1,0,0,0,7,54,1,0,0,0,9,56, - 1,0,0,0,11,59,1,0,0,0,13,64,1,0,0,0,15,69,1,0,0,0,17,76,1,0,0,0,19,79, - 1,0,0,0,21,88,1,0,0,0,23,96,1,0,0,0,25,102,1,0,0,0,27,107,1,0,0,0,29,117, - 1,0,0,0,31,125,1,0,0,0,33,158,1,0,0,0,35,160,1,0,0,0,37,178,1,0,0,0,39, - 187,1,0,0,0,41,189,1,0,0,0,43,198,1,0,0,0,45,46,5,58,0,0,46,2,1,0,0,0, - 47,48,5,101,0,0,48,49,5,113,0,0,49,50,5,117,0,0,50,4,1,0,0,0,51,52,5,100, - 0,0,52,53,5,119,0,0,53,6,1,0,0,0,54,55,5,44,0,0,55,8,1,0,0,0,56,57,5,100, - 0,0,57,58,5,98,0,0,58,10,1,0,0,0,59,60,5,114,0,0,60,61,5,101,0,0,61,62, - 5,115,0,0,62,63,5,98,0,0,63,12,1,0,0,0,64,65,5,114,0,0,65,66,5,101,0,0, - 66,67,5,115,0,0,67,68,5,119,0,0,68,14,1,0,0,0,69,70,5,111,0,0,70,71,5, - 102,0,0,71,72,5,102,0,0,72,73,5,115,0,0,73,74,5,101,0,0,74,75,5,116,0, - 0,75,16,1,0,0,0,76,77,5,48,0,0,77,78,5,120,0,0,78,18,1,0,0,0,79,80,5,37, - 0,0,80,81,5,105,0,0,81,82,5,110,0,0,82,83,5,99,0,0,83,84,5,108,0,0,84, - 85,5,117,0,0,85,86,5,100,0,0,86,87,5,101,0,0,87,20,1,0,0,0,88,89,5,115, - 0,0,89,90,5,101,0,0,90,91,5,99,0,0,91,92,5,116,0,0,92,93,5,105,0,0,93, - 94,5,111,0,0,94,95,5,110,0,0,95,22,1,0,0,0,96,97,5,46,0,0,97,98,5,116, - 0,0,98,99,5,101,0,0,99,100,5,120,0,0,100,101,5,116,0,0,101,24,1,0,0,0, - 102,103,5,46,0,0,103,104,5,98,0,0,104,105,5,115,0,0,105,106,5,115,0,0, - 106,26,1,0,0,0,107,111,5,39,0,0,108,110,8,0,0,0,109,108,1,0,0,0,110,113, - 1,0,0,0,111,109,1,0,0,0,111,112,1,0,0,0,112,114,1,0,0,0,113,111,1,0,0, - 0,114,115,5,39,0,0,115,28,1,0,0,0,116,118,7,1,0,0,117,116,1,0,0,0,117, - 118,1,0,0,0,118,120,1,0,0,0,119,121,7,2,0,0,120,119,1,0,0,0,121,122,1, - 0,0,0,122,120,1,0,0,0,122,123,1,0,0,0,123,30,1,0,0,0,124,126,7,3,0,0,125, - 124,1,0,0,0,126,127,1,0,0,0,127,125,1,0,0,0,127,128,1,0,0,0,128,32,1,0, - 0,0,129,131,7,1,0,0,130,129,1,0,0,0,130,131,1,0,0,0,131,135,1,0,0,0,132, - 134,7,2,0,0,133,132,1,0,0,0,134,137,1,0,0,0,135,133,1,0,0,0,135,136,1, - 0,0,0,136,138,1,0,0,0,137,135,1,0,0,0,138,140,5,46,0,0,139,141,7,2,0,0, - 140,139,1,0,0,0,141,142,1,0,0,0,142,140,1,0,0,0,142,143,1,0,0,0,143,159, - 1,0,0,0,144,146,7,2,0,0,145,144,1,0,0,0,146,147,1,0,0,0,147,145,1,0,0, - 0,147,148,1,0,0,0,148,149,1,0,0,0,149,151,7,4,0,0,150,152,7,1,0,0,151, - 150,1,0,0,0,151,152,1,0,0,0,152,154,1,0,0,0,153,155,7,2,0,0,154,153,1, - 0,0,0,155,156,1,0,0,0,156,154,1,0,0,0,156,157,1,0,0,0,157,159,1,0,0,0, - 158,130,1,0,0,0,158,145,1,0,0,0,159,34,1,0,0,0,160,164,7,5,0,0,161,163, - 7,6,0,0,162,161,1,0,0,0,163,166,1,0,0,0,164,162,1,0,0,0,164,165,1,0,0, - 0,165,175,1,0,0,0,166,164,1,0,0,0,167,169,5,46,0,0,168,170,7,6,0,0,169, - 168,1,0,0,0,170,171,1,0,0,0,171,169,1,0,0,0,171,172,1,0,0,0,172,174,1, - 0,0,0,173,167,1,0,0,0,174,177,1,0,0,0,175,173,1,0,0,0,175,176,1,0,0,0, - 176,36,1,0,0,0,177,175,1,0,0,0,178,179,7,7,0,0,179,180,1,0,0,0,180,181, - 6,18,0,0,181,38,1,0,0,0,182,184,5,13,0,0,183,182,1,0,0,0,183,184,1,0,0, - 0,184,185,1,0,0,0,185,188,5,10,0,0,186,188,5,13,0,0,187,183,1,0,0,0,187, - 186,1,0,0,0,188,40,1,0,0,0,189,193,5,34,0,0,190,192,8,8,0,0,191,190,1, - 0,0,0,192,195,1,0,0,0,193,191,1,0,0,0,193,194,1,0,0,0,194,196,1,0,0,0, - 195,193,1,0,0,0,196,197,5,34,0,0,197,42,1,0,0,0,198,202,5,59,0,0,199,201, - 8,9,0,0,200,199,1,0,0,0,201,204,1,0,0,0,202,200,1,0,0,0,202,203,1,0,0, - 0,203,205,1,0,0,0,204,202,1,0,0,0,205,206,6,21,0,0,206,44,1,0,0,0,19,0, - 111,117,122,127,130,135,142,147,151,156,158,164,171,175,183,187,193,202, - 1,6,0,0 - }; - - public static readonly ATN _ATN = - new ATNDeserializer().Deserialize(_serializedATN); - - -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// ANTLR Version: 4.13.2 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generated from BdxScript.g4 by ANTLR 4.13.2 + +// Unreachable code detected +#pragma warning disable 0162 +// The variable '...' is assigned but its value is never used +#pragma warning disable 0219 +// Missing XML comment for publicly visible type or member '...' +#pragma warning disable 1591 +// Ambiguous reference in cref attribute +#pragma warning disable 419 + +using System; +using System.IO; +using System.Text; +using Antlr4.Runtime; +using Antlr4.Runtime.Atn; +using Antlr4.Runtime.Misc; +using DFA = Antlr4.Runtime.Dfa.DFA; + +[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] +[System.CLSCompliant(false)] +public partial class BdxScriptLexer : Lexer { + protected static DFA[] decisionToDFA; + protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); + public const int + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, + T__9=10, T__10=11, T__11=12, T__12=13, StringData=14, DEC=15, HEX=16, + FLOATNUM=17, ID=18, WS=19, NL=20, FileName=21, LINE_COMMENT=22; + public static string[] channelNames = { + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }; + + public static string[] modeNames = { + "DEFAULT_MODE" + }; + + public static readonly string[] ruleNames = { + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "T__11", "T__12", "StringData", "DEC", "HEX", "FLOATNUM", + "ID", "WS", "NL", "FileName", "LINE_COMMENT" + }; + + + public BdxScriptLexer(ICharStream input) + : this(input, Console.Out, Console.Error) { } + + public BdxScriptLexer(ICharStream input, TextWriter output, TextWriter errorOutput) + : base(input, output, errorOutput) + { + Interpreter = new LexerATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); + } + + private static readonly string[] _LiteralNames = { + null, "':'", "'equ'", "'dw'", "','", "'db'", "'resb'", "'resw'", "'offset'", + "'0x'", "'%include'", "'section'", "'.text'", "'.bss'" + }; + private static readonly string[] _SymbolicNames = { + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, "StringData", "DEC", "HEX", "FLOATNUM", "ID", "WS", "NL", + "FileName", "LINE_COMMENT" + }; + public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); + + [NotNull] + public override IVocabulary Vocabulary + { + get + { + return DefaultVocabulary; + } + } + + public override string GrammarFileName { get { return "BdxScript.g4"; } } + + public override string[] RuleNames { get { return ruleNames; } } + + public override string[] ChannelNames { get { return channelNames; } } + + public override string[] ModeNames { get { return modeNames; } } + + public override int[] SerializedAtn { get { return _serializedATN; } } + + static BdxScriptLexer() { + decisionToDFA = new DFA[_ATN.NumberOfDecisions]; + for (int i = 0; i < _ATN.NumberOfDecisions; i++) { + decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); + } + } + private static int[] _serializedATN = { + 4,0,22,207,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, + 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, + 7,21,1,0,1,0,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,3,1,3,1,4,1,4,1,4,1,5,1,5,1, + 5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8, + 1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,10,1,10, + 1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,13,1,13, + 5,13,110,8,13,10,13,12,13,113,9,13,1,13,1,13,1,14,3,14,118,8,14,1,14,4, + 14,121,8,14,11,14,12,14,122,1,15,4,15,126,8,15,11,15,12,15,127,1,16,3, + 16,131,8,16,1,16,5,16,134,8,16,10,16,12,16,137,9,16,1,16,1,16,4,16,141, + 8,16,11,16,12,16,142,1,16,4,16,146,8,16,11,16,12,16,147,1,16,1,16,3,16, + 152,8,16,1,16,4,16,155,8,16,11,16,12,16,156,3,16,159,8,16,1,17,1,17,5, + 17,163,8,17,10,17,12,17,166,9,17,1,17,1,17,4,17,170,8,17,11,17,12,17,171, + 5,17,174,8,17,10,17,12,17,177,9,17,1,18,1,18,1,18,1,18,1,19,3,19,184,8, + 19,1,19,1,19,3,19,188,8,19,1,20,1,20,5,20,192,8,20,10,20,12,20,195,9,20, + 1,20,1,20,1,21,1,21,5,21,201,8,21,10,21,12,21,204,9,21,1,21,1,21,0,0,22, + 1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14, + 29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,1,0,10,1,0,39,39,2,0,43, + 43,45,45,1,0,48,57,3,0,48,57,65,70,97,102,2,0,69,69,101,101,3,0,65,90, + 95,95,97,122,4,0,48,57,65,90,95,95,97,122,2,0,9,9,32,32,1,0,34,34,2,0, + 10,10,13,13,224,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1, + 0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0, + 0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31, + 1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0, + 0,0,43,1,0,0,0,1,45,1,0,0,0,3,47,1,0,0,0,5,51,1,0,0,0,7,54,1,0,0,0,9,56, + 1,0,0,0,11,59,1,0,0,0,13,64,1,0,0,0,15,69,1,0,0,0,17,76,1,0,0,0,19,79, + 1,0,0,0,21,88,1,0,0,0,23,96,1,0,0,0,25,102,1,0,0,0,27,107,1,0,0,0,29,117, + 1,0,0,0,31,125,1,0,0,0,33,158,1,0,0,0,35,160,1,0,0,0,37,178,1,0,0,0,39, + 187,1,0,0,0,41,189,1,0,0,0,43,198,1,0,0,0,45,46,5,58,0,0,46,2,1,0,0,0, + 47,48,5,101,0,0,48,49,5,113,0,0,49,50,5,117,0,0,50,4,1,0,0,0,51,52,5,100, + 0,0,52,53,5,119,0,0,53,6,1,0,0,0,54,55,5,44,0,0,55,8,1,0,0,0,56,57,5,100, + 0,0,57,58,5,98,0,0,58,10,1,0,0,0,59,60,5,114,0,0,60,61,5,101,0,0,61,62, + 5,115,0,0,62,63,5,98,0,0,63,12,1,0,0,0,64,65,5,114,0,0,65,66,5,101,0,0, + 66,67,5,115,0,0,67,68,5,119,0,0,68,14,1,0,0,0,69,70,5,111,0,0,70,71,5, + 102,0,0,71,72,5,102,0,0,72,73,5,115,0,0,73,74,5,101,0,0,74,75,5,116,0, + 0,75,16,1,0,0,0,76,77,5,48,0,0,77,78,5,120,0,0,78,18,1,0,0,0,79,80,5,37, + 0,0,80,81,5,105,0,0,81,82,5,110,0,0,82,83,5,99,0,0,83,84,5,108,0,0,84, + 85,5,117,0,0,85,86,5,100,0,0,86,87,5,101,0,0,87,20,1,0,0,0,88,89,5,115, + 0,0,89,90,5,101,0,0,90,91,5,99,0,0,91,92,5,116,0,0,92,93,5,105,0,0,93, + 94,5,111,0,0,94,95,5,110,0,0,95,22,1,0,0,0,96,97,5,46,0,0,97,98,5,116, + 0,0,98,99,5,101,0,0,99,100,5,120,0,0,100,101,5,116,0,0,101,24,1,0,0,0, + 102,103,5,46,0,0,103,104,5,98,0,0,104,105,5,115,0,0,105,106,5,115,0,0, + 106,26,1,0,0,0,107,111,5,39,0,0,108,110,8,0,0,0,109,108,1,0,0,0,110,113, + 1,0,0,0,111,109,1,0,0,0,111,112,1,0,0,0,112,114,1,0,0,0,113,111,1,0,0, + 0,114,115,5,39,0,0,115,28,1,0,0,0,116,118,7,1,0,0,117,116,1,0,0,0,117, + 118,1,0,0,0,118,120,1,0,0,0,119,121,7,2,0,0,120,119,1,0,0,0,121,122,1, + 0,0,0,122,120,1,0,0,0,122,123,1,0,0,0,123,30,1,0,0,0,124,126,7,3,0,0,125, + 124,1,0,0,0,126,127,1,0,0,0,127,125,1,0,0,0,127,128,1,0,0,0,128,32,1,0, + 0,0,129,131,7,1,0,0,130,129,1,0,0,0,130,131,1,0,0,0,131,135,1,0,0,0,132, + 134,7,2,0,0,133,132,1,0,0,0,134,137,1,0,0,0,135,133,1,0,0,0,135,136,1, + 0,0,0,136,138,1,0,0,0,137,135,1,0,0,0,138,140,5,46,0,0,139,141,7,2,0,0, + 140,139,1,0,0,0,141,142,1,0,0,0,142,140,1,0,0,0,142,143,1,0,0,0,143,159, + 1,0,0,0,144,146,7,2,0,0,145,144,1,0,0,0,146,147,1,0,0,0,147,145,1,0,0, + 0,147,148,1,0,0,0,148,149,1,0,0,0,149,151,7,4,0,0,150,152,7,1,0,0,151, + 150,1,0,0,0,151,152,1,0,0,0,152,154,1,0,0,0,153,155,7,2,0,0,154,153,1, + 0,0,0,155,156,1,0,0,0,156,154,1,0,0,0,156,157,1,0,0,0,157,159,1,0,0,0, + 158,130,1,0,0,0,158,145,1,0,0,0,159,34,1,0,0,0,160,164,7,5,0,0,161,163, + 7,6,0,0,162,161,1,0,0,0,163,166,1,0,0,0,164,162,1,0,0,0,164,165,1,0,0, + 0,165,175,1,0,0,0,166,164,1,0,0,0,167,169,5,46,0,0,168,170,7,6,0,0,169, + 168,1,0,0,0,170,171,1,0,0,0,171,169,1,0,0,0,171,172,1,0,0,0,172,174,1, + 0,0,0,173,167,1,0,0,0,174,177,1,0,0,0,175,173,1,0,0,0,175,176,1,0,0,0, + 176,36,1,0,0,0,177,175,1,0,0,0,178,179,7,7,0,0,179,180,1,0,0,0,180,181, + 6,18,0,0,181,38,1,0,0,0,182,184,5,13,0,0,183,182,1,0,0,0,183,184,1,0,0, + 0,184,185,1,0,0,0,185,188,5,10,0,0,186,188,5,13,0,0,187,183,1,0,0,0,187, + 186,1,0,0,0,188,40,1,0,0,0,189,193,5,34,0,0,190,192,8,8,0,0,191,190,1, + 0,0,0,192,195,1,0,0,0,193,191,1,0,0,0,193,194,1,0,0,0,194,196,1,0,0,0, + 195,193,1,0,0,0,196,197,5,34,0,0,197,42,1,0,0,0,198,202,5,59,0,0,199,201, + 8,9,0,0,200,199,1,0,0,0,201,204,1,0,0,0,202,200,1,0,0,0,202,203,1,0,0, + 0,203,205,1,0,0,0,204,202,1,0,0,0,205,206,6,21,0,0,206,44,1,0,0,0,19,0, + 111,117,122,127,130,135,142,147,151,156,158,164,171,175,183,187,193,202, + 1,6,0,0 + }; + + public static readonly ATN _ATN = + new ATNDeserializer().Deserialize(_serializedATN); + + +} diff --git a/OpenKh.Command.Bdxio/Antlr4/BdxScriptParser.cs b/OpenKh.Kh2/Bdx/Antlr/BdxScriptParser.cs similarity index 95% rename from OpenKh.Command.Bdxio/Antlr4/BdxScriptParser.cs rename to OpenKh.Kh2/Bdx/Antlr/BdxScriptParser.cs index 5ec6fad21..5f65fa505 100644 --- a/OpenKh.Command.Bdxio/Antlr4/BdxScriptParser.cs +++ b/OpenKh.Kh2/Bdx/Antlr/BdxScriptParser.cs @@ -1,1240 +1,1240 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.11.1 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from BdxScript.g4 by ANTLR 4.11.1 - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 -// Ambiguous reference in cref attribute -#pragma warning disable 419 - -using System; -using System.IO; -using System.Text; -using System.Diagnostics; -using System.Collections.Generic; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using DFA = Antlr4.Runtime.Dfa.DFA; - -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.11.1")] -[System.CLSCompliant(false)] -public partial class BdxScriptParser : Parser { - protected static DFA[] decisionToDFA; - protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); - public const int - T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, - T__9=10, T__10=11, T__11=12, T__12=13, StringData=14, DEC=15, HEX=16, - FLOATNUM=17, ID=18, WS=19, NL=20, FileName=21, LINE_COMMENT=22; - public const int - RULE_prog = 0, RULE_statement = 1, RULE_label = 2, RULE_equ = 3, RULE_order = 4, - RULE_dw = 5, RULE_db = 6, RULE_resb = 7, RULE_resw = 8, RULE_instruction = 9, - RULE_arg = 10, RULE_offset = 11, RULE_bytedata = 12, RULE_worddata = 13, - RULE_numberdata = 14, RULE_hexbody = 15, RULE_id = 16, RULE_include = 17, - RULE_section = 18, RULE_section_id = 19; - public static readonly string[] ruleNames = { - "prog", "statement", "label", "equ", "order", "dw", "db", "resb", "resw", - "instruction", "arg", "offset", "bytedata", "worddata", "numberdata", - "hexbody", "id", "include", "section", "section_id" - }; - - private static readonly string[] _LiteralNames = { - null, "':'", "'equ'", "'dw'", "','", "'db'", "'resb'", "'resw'", "'offset'", - "'0x'", "'%include'", "'section'", "'.text'", "'.bss'" - }; - private static readonly string[] _SymbolicNames = { - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, "StringData", "DEC", "HEX", "FLOATNUM", "ID", "WS", "NL", - "FileName", "LINE_COMMENT" - }; - public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); - - [NotNull] - public override IVocabulary Vocabulary - { - get - { - return DefaultVocabulary; - } - } - - public override string GrammarFileName { get { return "BdxScript.g4"; } } - - public override string[] RuleNames { get { return ruleNames; } } - - public override int[] SerializedAtn { get { return _serializedATN; } } - - static BdxScriptParser() { - decisionToDFA = new DFA[_ATN.NumberOfDecisions]; - for (int i = 0; i < _ATN.NumberOfDecisions; i++) { - decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); - } - } - - public BdxScriptParser(ITokenStream input) : this(input, Console.Out, Console.Error) { } - - public BdxScriptParser(ITokenStream input, TextWriter output, TextWriter errorOutput) - : base(input, output, errorOutput) - { - Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); - } - - public partial class ProgContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode Eof() { return GetToken(BdxScriptParser.Eof, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] NL() { return GetTokens(BdxScriptParser.NL); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL(int i) { - return GetToken(BdxScriptParser.NL, i); - } - [System.Diagnostics.DebuggerNonUserCode] public StatementContext[] statement() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement(int i) { - return GetRuleContext(i); - } - public ProgContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_prog; } } - } - - [RuleVersion(0)] - public ProgContext prog() { - ProgContext _localctx = new ProgContext(Context, State); - EnterRule(_localctx, 0, RULE_prog); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 43; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==NL) { - { - { - State = 40; - Match(NL); - } - } - State = 45; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - State = 55; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (((_la) & ~0x3f) == 0 && ((1L << _la) & 363752L) != 0) { - { - { - State = 46; - statement(); - State = 50; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==NL) { - { - { - State = 47; - Match(NL); - } - } - State = 52; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - } - } - State = 57; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - State = 58; - Match(Eof); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class StatementContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public SectionContext section() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public EquContext equ() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public LabelContext label() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - [System.Diagnostics.DebuggerNonUserCode] public OrderContext order() { - return GetRuleContext(0); - } - public StatementContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_statement; } } - } - - [RuleVersion(0)] - public StatementContext statement() { - StatementContext _localctx = new StatementContext(Context, State); - EnterRule(_localctx, 2, RULE_statement); - try { - State = 71; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,3,Context) ) { - case 1: - EnterOuterAlt(_localctx, 1); - { - State = 60; - section(); - } - break; - case 2: - EnterOuterAlt(_localctx, 2); - { - State = 61; - equ(); - } - break; - case 3: - EnterOuterAlt(_localctx, 3); - { - State = 62; - label(); - State = 63; - Match(T__0); - State = 64; - Match(NL); - } - break; - case 4: - EnterOuterAlt(_localctx, 4); - { - State = 66; - label(); - State = 67; - Match(T__0); - State = 68; - order(); - } - break; - case 5: - EnterOuterAlt(_localctx, 5); - { - State = 70; - order(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class LabelContext : ParserRuleContext { - public IdContext name; - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public LabelContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_label; } } - } - - [RuleVersion(0)] - public LabelContext label() { - LabelContext _localctx = new LabelContext(Context, State); - EnterRule(_localctx, 4, RULE_label); - try { - EnterOuterAlt(_localctx, 1); - { - State = 73; - _localctx.name = id(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class EquContext : ParserRuleContext { - public IdContext name; - [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public EquContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_equ; } } - } - - [RuleVersion(0)] - public EquContext equ() { - EquContext _localctx = new EquContext(Context, State); - EnterRule(_localctx, 6, RULE_equ); - try { - EnterOuterAlt(_localctx, 1); - { - State = 75; - _localctx.name = id(); - State = 76; - Match(T__1); - State = 77; - numberdata(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class OrderContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public DbContext db() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ResbContext resb() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public DwContext dw() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ReswContext resw() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public InstructionContext instruction() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IncludeContext include() { - return GetRuleContext(0); - } - public OrderContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_order; } } - } - - [RuleVersion(0)] - public OrderContext order() { - OrderContext _localctx = new OrderContext(Context, State); - EnterRule(_localctx, 8, RULE_order); - try { - State = 85; - ErrorHandler.Sync(this); - switch (TokenStream.LA(1)) { - case T__4: - EnterOuterAlt(_localctx, 1); - { - State = 79; - db(); - } - break; - case T__5: - EnterOuterAlt(_localctx, 2); - { - State = 80; - resb(); - } - break; - case T__2: - EnterOuterAlt(_localctx, 3); - { - State = 81; - dw(); - } - break; - case T__6: - EnterOuterAlt(_localctx, 4); - { - State = 82; - resw(); - } - break; - case DEC: - case HEX: - case ID: - EnterOuterAlt(_localctx, 5); - { - State = 83; - instruction(); - } - break; - case T__9: - EnterOuterAlt(_localctx, 6); - { - State = 84; - include(); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class DwContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public WorddataContext[] worddata() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public WorddataContext worddata(int i) { - return GetRuleContext(i); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - public DwContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_dw; } } - } - - [RuleVersion(0)] - public DwContext dw() { - DwContext _localctx = new DwContext(Context, State); - EnterRule(_localctx, 10, RULE_dw); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 87; - Match(T__2); - State = 88; - worddata(); - State = 93; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__3) { - { - { - State = 89; - Match(T__3); - State = 90; - worddata(); - } - } - State = 95; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - State = 96; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class DbContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public BytedataContext[] bytedata() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public BytedataContext bytedata(int i) { - return GetRuleContext(i); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - public DbContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_db; } } - } - - [RuleVersion(0)] - public DbContext db() { - DbContext _localctx = new DbContext(Context, State); - EnterRule(_localctx, 12, RULE_db); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 98; - Match(T__4); - State = 99; - bytedata(); - State = 104; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__3) { - { - { - State = 100; - Match(T__3); - State = 101; - bytedata(); - } - } - State = 106; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - State = 107; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class ResbContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public ResbContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_resb; } } - } - - [RuleVersion(0)] - public ResbContext resb() { - ResbContext _localctx = new ResbContext(Context, State); - EnterRule(_localctx, 14, RULE_resb); - try { - EnterOuterAlt(_localctx, 1); - { - State = 109; - Match(T__5); - State = 112; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,7,Context) ) { - case 1: - { - State = 110; - numberdata(); - } - break; - case 2: - { - State = 111; - id(); - } - break; - } - State = 114; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class ReswContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public ReswContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_resw; } } - } - - [RuleVersion(0)] - public ReswContext resw() { - ReswContext _localctx = new ReswContext(Context, State); - EnterRule(_localctx, 16, RULE_resw); - try { - EnterOuterAlt(_localctx, 1); - { - State = 116; - Match(T__6); - State = 119; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,8,Context) ) { - case 1: - { - State = 117; - numberdata(); - } - break; - case 2: - { - State = 118; - id(); - } - break; - } - State = 121; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class InstructionContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ArgContext[] arg() { - return GetRuleContexts(); - } - [System.Diagnostics.DebuggerNonUserCode] public ArgContext arg(int i) { - return GetRuleContext(i); - } - public InstructionContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_instruction; } } - } - - [RuleVersion(0)] - public InstructionContext instruction() { - InstructionContext _localctx = new InstructionContext(Context, State); - EnterRule(_localctx, 18, RULE_instruction); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 123; - id(); - State = 132; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - if (((_la) & ~0x3f) == 0 && ((1L << _la) & 492032L) != 0) { - { - State = 124; - arg(); - State = 129; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - while (_la==T__3) { - { - { - State = 125; - Match(T__3); - State = 126; - arg(); - } - } - State = 131; - ErrorHandler.Sync(this); - _la = TokenStream.LA(1); - } - } - } - - State = 134; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class ArgContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public ArgContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_arg; } } - } - - [RuleVersion(0)] - public ArgContext arg() { - ArgContext _localctx = new ArgContext(Context, State); - EnterRule(_localctx, 20, RULE_arg); - try { - EnterOuterAlt(_localctx, 1); - { - State = 138; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,11,Context) ) { - case 1: - { - State = 136; - numberdata(); - } - break; - case 2: - { - State = 137; - id(); - } - break; - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class OffsetContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public OffsetContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_offset; } } - } - - [RuleVersion(0)] - public OffsetContext offset() { - OffsetContext _localctx = new OffsetContext(Context, State); - EnterRule(_localctx, 22, RULE_offset); - try { - EnterOuterAlt(_localctx, 1); - { - State = 140; - Match(T__7); - State = 141; - id(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class BytedataContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode StringData() { return GetToken(BdxScriptParser.StringData, 0); } - public BytedataContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_bytedata; } } - } - - [RuleVersion(0)] - public BytedataContext bytedata() { - BytedataContext _localctx = new BytedataContext(Context, State); - EnterRule(_localctx, 24, RULE_bytedata); - try { - State = 146; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,12,Context) ) { - case 1: - EnterOuterAlt(_localctx, 1); - { - State = 143; - numberdata(); - } - break; - case 2: - EnterOuterAlt(_localctx, 2); - { - State = 144; - id(); - } - break; - case 3: - EnterOuterAlt(_localctx, 3); - { - State = 145; - Match(StringData); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class WorddataContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { - return GetRuleContext(0); - } - public WorddataContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_worddata; } } - } - - [RuleVersion(0)] - public WorddataContext worddata() { - WorddataContext _localctx = new WorddataContext(Context, State); - EnterRule(_localctx, 26, RULE_worddata); - try { - State = 150; - ErrorHandler.Sync(this); - switch ( Interpreter.AdaptivePredict(TokenStream,13,Context) ) { - case 1: - EnterOuterAlt(_localctx, 1); - { - State = 148; - numberdata(); - } - break; - case 2: - EnterOuterAlt(_localctx, 2); - { - State = 149; - id(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class NumberdataContext : ParserRuleContext { - public IToken decimalnumber; - public IToken hexnumber; - public IToken floatnumber; - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode FLOATNUM() { return GetToken(BdxScriptParser.FLOATNUM, 0); } - public NumberdataContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_numberdata; } } - } - - [RuleVersion(0)] - public NumberdataContext numberdata() { - NumberdataContext _localctx = new NumberdataContext(Context, State); - EnterRule(_localctx, 28, RULE_numberdata); - int _la; - try { - State = 156; - ErrorHandler.Sync(this); - switch (TokenStream.LA(1)) { - case DEC: - EnterOuterAlt(_localctx, 1); - { - State = 152; - _localctx.decimalnumber = Match(DEC); - } - break; - case T__8: - EnterOuterAlt(_localctx, 2); - { - State = 153; - Match(T__8); - State = 154; - _localctx.hexnumber = TokenStream.LT(1); - _la = TokenStream.LA(1); - if ( !(_la==DEC || _la==HEX) ) { - _localctx.hexnumber = ErrorHandler.RecoverInline(this); - } - else { - ErrorHandler.ReportMatch(this); - Consume(); - } - } - break; - case FLOATNUM: - EnterOuterAlt(_localctx, 3); - { - State = 155; - _localctx.floatnumber = Match(FLOATNUM); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class HexbodyContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); } - public HexbodyContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_hexbody; } } - } - - [RuleVersion(0)] - public HexbodyContext hexbody() { - HexbodyContext _localctx = new HexbodyContext(Context, State); - EnterRule(_localctx, 30, RULE_hexbody); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 158; - _la = TokenStream.LA(1); - if ( !(_la==DEC || _la==HEX) ) { - ErrorHandler.RecoverInline(this); - } - else { - ErrorHandler.ReportMatch(this); - Consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class IdContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(BdxScriptParser.ID, 0); } - public IdContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_id; } } - } - - [RuleVersion(0)] - public IdContext id() { - IdContext _localctx = new IdContext(Context, State); - EnterRule(_localctx, 32, RULE_id); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 160; - _la = TokenStream.LA(1); - if ( !(((_la) & ~0x3f) == 0 && ((1L << _la) & 360448L) != 0) ) { - ErrorHandler.RecoverInline(this); - } - else { - ErrorHandler.ReportMatch(this); - Consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class IncludeContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode FileName() { return GetToken(BdxScriptParser.FileName, 0); } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - public IncludeContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_include; } } - } - - [RuleVersion(0)] - public IncludeContext include() { - IncludeContext _localctx = new IncludeContext(Context, State); - EnterRule(_localctx, 34, RULE_include); - try { - EnterOuterAlt(_localctx, 1); - { - State = 162; - Match(T__9); - State = 163; - Match(FileName); - State = 164; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class SectionContext : ParserRuleContext { - [System.Diagnostics.DebuggerNonUserCode] public Section_idContext section_id() { - return GetRuleContext(0); - } - [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } - public SectionContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_section; } } - } - - [RuleVersion(0)] - public SectionContext section() { - SectionContext _localctx = new SectionContext(Context, State); - EnterRule(_localctx, 36, RULE_section); - try { - EnterOuterAlt(_localctx, 1); - { - State = 166; - Match(T__10); - State = 167; - section_id(); - State = 168; - Match(NL); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class Section_idContext : ParserRuleContext { - public Section_idContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_section_id; } } - } - - [RuleVersion(0)] - public Section_idContext section_id() { - Section_idContext _localctx = new Section_idContext(Context, State); - EnterRule(_localctx, 38, RULE_section_id); - int _la; - try { - EnterOuterAlt(_localctx, 1); - { - State = 170; - _la = TokenStream.LA(1); - if ( !(_la==T__11 || _la==T__12) ) { - ErrorHandler.RecoverInline(this); - } - else { - ErrorHandler.ReportMatch(this); - Consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - private static int[] _serializedATN = { - 4,1,22,173,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7, - 7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14, - 2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,1,0,5,0,42,8,0,10,0, - 12,0,45,9,0,1,0,1,0,5,0,49,8,0,10,0,12,0,52,9,0,5,0,54,8,0,10,0,12,0,57, - 9,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,72,8,1,1,2, - 1,2,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,4,3,4,86,8,4,1,5,1,5,1,5,1,5, - 5,5,92,8,5,10,5,12,5,95,9,5,1,5,1,5,1,6,1,6,1,6,1,6,5,6,103,8,6,10,6,12, - 6,106,9,6,1,6,1,6,1,7,1,7,1,7,3,7,113,8,7,1,7,1,7,1,8,1,8,1,8,3,8,120, - 8,8,1,8,1,8,1,9,1,9,1,9,1,9,5,9,128,8,9,10,9,12,9,131,9,9,3,9,133,8,9, - 1,9,1,9,1,10,1,10,3,10,139,8,10,1,11,1,11,1,11,1,12,1,12,1,12,3,12,147, - 8,12,1,13,1,13,3,13,151,8,13,1,14,1,14,1,14,1,14,3,14,157,8,14,1,15,1, - 15,1,16,1,16,1,17,1,17,1,17,1,17,1,18,1,18,1,18,1,18,1,19,1,19,1,19,0, - 0,20,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,0,3,1,0,15, - 16,2,0,15,16,18,18,1,0,12,13,176,0,43,1,0,0,0,2,71,1,0,0,0,4,73,1,0,0, - 0,6,75,1,0,0,0,8,85,1,0,0,0,10,87,1,0,0,0,12,98,1,0,0,0,14,109,1,0,0,0, - 16,116,1,0,0,0,18,123,1,0,0,0,20,138,1,0,0,0,22,140,1,0,0,0,24,146,1,0, - 0,0,26,150,1,0,0,0,28,156,1,0,0,0,30,158,1,0,0,0,32,160,1,0,0,0,34,162, - 1,0,0,0,36,166,1,0,0,0,38,170,1,0,0,0,40,42,5,20,0,0,41,40,1,0,0,0,42, - 45,1,0,0,0,43,41,1,0,0,0,43,44,1,0,0,0,44,55,1,0,0,0,45,43,1,0,0,0,46, - 50,3,2,1,0,47,49,5,20,0,0,48,47,1,0,0,0,49,52,1,0,0,0,50,48,1,0,0,0,50, - 51,1,0,0,0,51,54,1,0,0,0,52,50,1,0,0,0,53,46,1,0,0,0,54,57,1,0,0,0,55, - 53,1,0,0,0,55,56,1,0,0,0,56,58,1,0,0,0,57,55,1,0,0,0,58,59,5,0,0,1,59, - 1,1,0,0,0,60,72,3,36,18,0,61,72,3,6,3,0,62,63,3,4,2,0,63,64,5,1,0,0,64, - 65,5,20,0,0,65,72,1,0,0,0,66,67,3,4,2,0,67,68,5,1,0,0,68,69,3,8,4,0,69, - 72,1,0,0,0,70,72,3,8,4,0,71,60,1,0,0,0,71,61,1,0,0,0,71,62,1,0,0,0,71, - 66,1,0,0,0,71,70,1,0,0,0,72,3,1,0,0,0,73,74,3,32,16,0,74,5,1,0,0,0,75, - 76,3,32,16,0,76,77,5,2,0,0,77,78,3,28,14,0,78,7,1,0,0,0,79,86,3,12,6,0, - 80,86,3,14,7,0,81,86,3,10,5,0,82,86,3,16,8,0,83,86,3,18,9,0,84,86,3,34, - 17,0,85,79,1,0,0,0,85,80,1,0,0,0,85,81,1,0,0,0,85,82,1,0,0,0,85,83,1,0, - 0,0,85,84,1,0,0,0,86,9,1,0,0,0,87,88,5,3,0,0,88,93,3,26,13,0,89,90,5,4, - 0,0,90,92,3,26,13,0,91,89,1,0,0,0,92,95,1,0,0,0,93,91,1,0,0,0,93,94,1, - 0,0,0,94,96,1,0,0,0,95,93,1,0,0,0,96,97,5,20,0,0,97,11,1,0,0,0,98,99,5, - 5,0,0,99,104,3,24,12,0,100,101,5,4,0,0,101,103,3,24,12,0,102,100,1,0,0, - 0,103,106,1,0,0,0,104,102,1,0,0,0,104,105,1,0,0,0,105,107,1,0,0,0,106, - 104,1,0,0,0,107,108,5,20,0,0,108,13,1,0,0,0,109,112,5,6,0,0,110,113,3, - 28,14,0,111,113,3,32,16,0,112,110,1,0,0,0,112,111,1,0,0,0,113,114,1,0, - 0,0,114,115,5,20,0,0,115,15,1,0,0,0,116,119,5,7,0,0,117,120,3,28,14,0, - 118,120,3,32,16,0,119,117,1,0,0,0,119,118,1,0,0,0,120,121,1,0,0,0,121, - 122,5,20,0,0,122,17,1,0,0,0,123,132,3,32,16,0,124,129,3,20,10,0,125,126, - 5,4,0,0,126,128,3,20,10,0,127,125,1,0,0,0,128,131,1,0,0,0,129,127,1,0, - 0,0,129,130,1,0,0,0,130,133,1,0,0,0,131,129,1,0,0,0,132,124,1,0,0,0,132, - 133,1,0,0,0,133,134,1,0,0,0,134,135,5,20,0,0,135,19,1,0,0,0,136,139,3, - 28,14,0,137,139,3,32,16,0,138,136,1,0,0,0,138,137,1,0,0,0,139,21,1,0,0, - 0,140,141,5,8,0,0,141,142,3,32,16,0,142,23,1,0,0,0,143,147,3,28,14,0,144, - 147,3,32,16,0,145,147,5,14,0,0,146,143,1,0,0,0,146,144,1,0,0,0,146,145, - 1,0,0,0,147,25,1,0,0,0,148,151,3,28,14,0,149,151,3,32,16,0,150,148,1,0, - 0,0,150,149,1,0,0,0,151,27,1,0,0,0,152,157,5,15,0,0,153,154,5,9,0,0,154, - 157,7,0,0,0,155,157,5,17,0,0,156,152,1,0,0,0,156,153,1,0,0,0,156,155,1, - 0,0,0,157,29,1,0,0,0,158,159,7,0,0,0,159,31,1,0,0,0,160,161,7,1,0,0,161, - 33,1,0,0,0,162,163,5,10,0,0,163,164,5,21,0,0,164,165,5,20,0,0,165,35,1, - 0,0,0,166,167,5,11,0,0,167,168,3,38,19,0,168,169,5,20,0,0,169,37,1,0,0, - 0,170,171,7,2,0,0,171,39,1,0,0,0,15,43,50,55,71,85,93,104,112,119,129, - 132,138,146,150,156 - }; - - public static readonly ATN _ATN = - new ATNDeserializer().Deserialize(_serializedATN); - - -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// ANTLR Version: 4.13.2 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generated from BdxScript.g4 by ANTLR 4.13.2 + +// Unreachable code detected +#pragma warning disable 0162 +// The variable '...' is assigned but its value is never used +#pragma warning disable 0219 +// Missing XML comment for publicly visible type or member '...' +#pragma warning disable 1591 +// Ambiguous reference in cref attribute +#pragma warning disable 419 + +using System; +using System.IO; +using System.Text; +using System.Diagnostics; +using System.Collections.Generic; +using Antlr4.Runtime; +using Antlr4.Runtime.Atn; +using Antlr4.Runtime.Misc; +using Antlr4.Runtime.Tree; +using DFA = Antlr4.Runtime.Dfa.DFA; + +[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.13.2")] +[System.CLSCompliant(false)] +public partial class BdxScriptParser : Parser { + protected static DFA[] decisionToDFA; + protected static PredictionContextCache sharedContextCache = new PredictionContextCache(); + public const int + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, + T__9=10, T__10=11, T__11=12, T__12=13, StringData=14, DEC=15, HEX=16, + FLOATNUM=17, ID=18, WS=19, NL=20, FileName=21, LINE_COMMENT=22; + public const int + RULE_prog = 0, RULE_statement = 1, RULE_label = 2, RULE_equ = 3, RULE_order = 4, + RULE_dw = 5, RULE_db = 6, RULE_resb = 7, RULE_resw = 8, RULE_instruction = 9, + RULE_arg = 10, RULE_offset = 11, RULE_bytedata = 12, RULE_worddata = 13, + RULE_numberdata = 14, RULE_hexbody = 15, RULE_id = 16, RULE_include = 17, + RULE_section = 18, RULE_section_id = 19; + public static readonly string[] ruleNames = { + "prog", "statement", "label", "equ", "order", "dw", "db", "resb", "resw", + "instruction", "arg", "offset", "bytedata", "worddata", "numberdata", + "hexbody", "id", "include", "section", "section_id" + }; + + private static readonly string[] _LiteralNames = { + null, "':'", "'equ'", "'dw'", "','", "'db'", "'resb'", "'resw'", "'offset'", + "'0x'", "'%include'", "'section'", "'.text'", "'.bss'" + }; + private static readonly string[] _SymbolicNames = { + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, "StringData", "DEC", "HEX", "FLOATNUM", "ID", "WS", "NL", + "FileName", "LINE_COMMENT" + }; + public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); + + [NotNull] + public override IVocabulary Vocabulary + { + get + { + return DefaultVocabulary; + } + } + + public override string GrammarFileName { get { return "BdxScript.g4"; } } + + public override string[] RuleNames { get { return ruleNames; } } + + public override int[] SerializedAtn { get { return _serializedATN; } } + + static BdxScriptParser() { + decisionToDFA = new DFA[_ATN.NumberOfDecisions]; + for (int i = 0; i < _ATN.NumberOfDecisions; i++) { + decisionToDFA[i] = new DFA(_ATN.GetDecisionState(i), i); + } + } + + public BdxScriptParser(ITokenStream input) : this(input, Console.Out, Console.Error) { } + + public BdxScriptParser(ITokenStream input, TextWriter output, TextWriter errorOutput) + : base(input, output, errorOutput) + { + Interpreter = new ParserATNSimulator(this, _ATN, decisionToDFA, sharedContextCache); + } + + public partial class ProgContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode Eof() { return GetToken(BdxScriptParser.Eof, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode[] NL() { return GetTokens(BdxScriptParser.NL); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL(int i) { + return GetToken(BdxScriptParser.NL, i); + } + [System.Diagnostics.DebuggerNonUserCode] public StatementContext[] statement() { + return GetRuleContexts(); + } + [System.Diagnostics.DebuggerNonUserCode] public StatementContext statement(int i) { + return GetRuleContext(i); + } + public ProgContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_prog; } } + } + + [RuleVersion(0)] + public ProgContext prog() { + ProgContext _localctx = new ProgContext(Context, State); + EnterRule(_localctx, 0, RULE_prog); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 43; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while (_la==NL) { + { + { + State = 40; + Match(NL); + } + } + State = 45; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + State = 55; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 363752L) != 0)) { + { + { + State = 46; + statement(); + State = 50; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while (_la==NL) { + { + { + State = 47; + Match(NL); + } + } + State = 52; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + } + } + State = 57; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + State = 58; + Match(Eof); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class StatementContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public SectionContext section() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public EquContext equ() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public LabelContext label() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + [System.Diagnostics.DebuggerNonUserCode] public OrderContext order() { + return GetRuleContext(0); + } + public StatementContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_statement; } } + } + + [RuleVersion(0)] + public StatementContext statement() { + StatementContext _localctx = new StatementContext(Context, State); + EnterRule(_localctx, 2, RULE_statement); + try { + State = 71; + ErrorHandler.Sync(this); + switch ( Interpreter.AdaptivePredict(TokenStream,3,Context) ) { + case 1: + EnterOuterAlt(_localctx, 1); + { + State = 60; + section(); + } + break; + case 2: + EnterOuterAlt(_localctx, 2); + { + State = 61; + equ(); + } + break; + case 3: + EnterOuterAlt(_localctx, 3); + { + State = 62; + label(); + State = 63; + Match(T__0); + State = 64; + Match(NL); + } + break; + case 4: + EnterOuterAlt(_localctx, 4); + { + State = 66; + label(); + State = 67; + Match(T__0); + State = 68; + order(); + } + break; + case 5: + EnterOuterAlt(_localctx, 5); + { + State = 70; + order(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class LabelContext : ParserRuleContext { + public IdContext name; + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public LabelContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_label; } } + } + + [RuleVersion(0)] + public LabelContext label() { + LabelContext _localctx = new LabelContext(Context, State); + EnterRule(_localctx, 4, RULE_label); + try { + EnterOuterAlt(_localctx, 1); + { + State = 73; + _localctx.name = id(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class EquContext : ParserRuleContext { + public IdContext name; + [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public EquContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_equ; } } + } + + [RuleVersion(0)] + public EquContext equ() { + EquContext _localctx = new EquContext(Context, State); + EnterRule(_localctx, 6, RULE_equ); + try { + EnterOuterAlt(_localctx, 1); + { + State = 75; + _localctx.name = id(); + State = 76; + Match(T__1); + State = 77; + numberdata(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class OrderContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public DbContext db() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ResbContext resb() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public DwContext dw() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ReswContext resw() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public InstructionContext instruction() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IncludeContext include() { + return GetRuleContext(0); + } + public OrderContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_order; } } + } + + [RuleVersion(0)] + public OrderContext order() { + OrderContext _localctx = new OrderContext(Context, State); + EnterRule(_localctx, 8, RULE_order); + try { + State = 85; + ErrorHandler.Sync(this); + switch (TokenStream.LA(1)) { + case T__4: + EnterOuterAlt(_localctx, 1); + { + State = 79; + db(); + } + break; + case T__5: + EnterOuterAlt(_localctx, 2); + { + State = 80; + resb(); + } + break; + case T__2: + EnterOuterAlt(_localctx, 3); + { + State = 81; + dw(); + } + break; + case T__6: + EnterOuterAlt(_localctx, 4); + { + State = 82; + resw(); + } + break; + case DEC: + case HEX: + case ID: + EnterOuterAlt(_localctx, 5); + { + State = 83; + instruction(); + } + break; + case T__9: + EnterOuterAlt(_localctx, 6); + { + State = 84; + include(); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class DwContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public WorddataContext[] worddata() { + return GetRuleContexts(); + } + [System.Diagnostics.DebuggerNonUserCode] public WorddataContext worddata(int i) { + return GetRuleContext(i); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + public DwContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_dw; } } + } + + [RuleVersion(0)] + public DwContext dw() { + DwContext _localctx = new DwContext(Context, State); + EnterRule(_localctx, 10, RULE_dw); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 87; + Match(T__2); + State = 88; + worddata(); + State = 93; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while (_la==T__3) { + { + { + State = 89; + Match(T__3); + State = 90; + worddata(); + } + } + State = 95; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + State = 96; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class DbContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public BytedataContext[] bytedata() { + return GetRuleContexts(); + } + [System.Diagnostics.DebuggerNonUserCode] public BytedataContext bytedata(int i) { + return GetRuleContext(i); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + public DbContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_db; } } + } + + [RuleVersion(0)] + public DbContext db() { + DbContext _localctx = new DbContext(Context, State); + EnterRule(_localctx, 12, RULE_db); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 98; + Match(T__4); + State = 99; + bytedata(); + State = 104; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while (_la==T__3) { + { + { + State = 100; + Match(T__3); + State = 101; + bytedata(); + } + } + State = 106; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + State = 107; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class ResbContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public ResbContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_resb; } } + } + + [RuleVersion(0)] + public ResbContext resb() { + ResbContext _localctx = new ResbContext(Context, State); + EnterRule(_localctx, 14, RULE_resb); + try { + EnterOuterAlt(_localctx, 1); + { + State = 109; + Match(T__5); + State = 112; + ErrorHandler.Sync(this); + switch ( Interpreter.AdaptivePredict(TokenStream,7,Context) ) { + case 1: + { + State = 110; + numberdata(); + } + break; + case 2: + { + State = 111; + id(); + } + break; + } + State = 114; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class ReswContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public ReswContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_resw; } } + } + + [RuleVersion(0)] + public ReswContext resw() { + ReswContext _localctx = new ReswContext(Context, State); + EnterRule(_localctx, 16, RULE_resw); + try { + EnterOuterAlt(_localctx, 1); + { + State = 116; + Match(T__6); + State = 119; + ErrorHandler.Sync(this); + switch ( Interpreter.AdaptivePredict(TokenStream,8,Context) ) { + case 1: + { + State = 117; + numberdata(); + } + break; + case 2: + { + State = 118; + id(); + } + break; + } + State = 121; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class InstructionContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ArgContext[] arg() { + return GetRuleContexts(); + } + [System.Diagnostics.DebuggerNonUserCode] public ArgContext arg(int i) { + return GetRuleContext(i); + } + public InstructionContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_instruction; } } + } + + [RuleVersion(0)] + public InstructionContext instruction() { + InstructionContext _localctx = new InstructionContext(Context, State); + EnterRule(_localctx, 18, RULE_instruction); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 123; + id(); + State = 132; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 492032L) != 0)) { + { + State = 124; + arg(); + State = 129; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + while (_la==T__3) { + { + { + State = 125; + Match(T__3); + State = 126; + arg(); + } + } + State = 131; + ErrorHandler.Sync(this); + _la = TokenStream.LA(1); + } + } + } + + State = 134; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class ArgContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public ArgContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_arg; } } + } + + [RuleVersion(0)] + public ArgContext arg() { + ArgContext _localctx = new ArgContext(Context, State); + EnterRule(_localctx, 20, RULE_arg); + try { + EnterOuterAlt(_localctx, 1); + { + State = 138; + ErrorHandler.Sync(this); + switch ( Interpreter.AdaptivePredict(TokenStream,11,Context) ) { + case 1: + { + State = 136; + numberdata(); + } + break; + case 2: + { + State = 137; + id(); + } + break; + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class OffsetContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public OffsetContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_offset; } } + } + + [RuleVersion(0)] + public OffsetContext offset() { + OffsetContext _localctx = new OffsetContext(Context, State); + EnterRule(_localctx, 22, RULE_offset); + try { + EnterOuterAlt(_localctx, 1); + { + State = 140; + Match(T__7); + State = 141; + id(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class BytedataContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode StringData() { return GetToken(BdxScriptParser.StringData, 0); } + public BytedataContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_bytedata; } } + } + + [RuleVersion(0)] + public BytedataContext bytedata() { + BytedataContext _localctx = new BytedataContext(Context, State); + EnterRule(_localctx, 24, RULE_bytedata); + try { + State = 146; + ErrorHandler.Sync(this); + switch ( Interpreter.AdaptivePredict(TokenStream,12,Context) ) { + case 1: + EnterOuterAlt(_localctx, 1); + { + State = 143; + numberdata(); + } + break; + case 2: + EnterOuterAlt(_localctx, 2); + { + State = 144; + id(); + } + break; + case 3: + EnterOuterAlt(_localctx, 3); + { + State = 145; + Match(StringData); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class WorddataContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public NumberdataContext numberdata() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public IdContext id() { + return GetRuleContext(0); + } + public WorddataContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_worddata; } } + } + + [RuleVersion(0)] + public WorddataContext worddata() { + WorddataContext _localctx = new WorddataContext(Context, State); + EnterRule(_localctx, 26, RULE_worddata); + try { + State = 150; + ErrorHandler.Sync(this); + switch ( Interpreter.AdaptivePredict(TokenStream,13,Context) ) { + case 1: + EnterOuterAlt(_localctx, 1); + { + State = 148; + numberdata(); + } + break; + case 2: + EnterOuterAlt(_localctx, 2); + { + State = 149; + id(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class NumberdataContext : ParserRuleContext { + public IToken decimalnumber; + public IToken hexnumber; + public IToken floatnumber; + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode FLOATNUM() { return GetToken(BdxScriptParser.FLOATNUM, 0); } + public NumberdataContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_numberdata; } } + } + + [RuleVersion(0)] + public NumberdataContext numberdata() { + NumberdataContext _localctx = new NumberdataContext(Context, State); + EnterRule(_localctx, 28, RULE_numberdata); + int _la; + try { + State = 156; + ErrorHandler.Sync(this); + switch (TokenStream.LA(1)) { + case DEC: + EnterOuterAlt(_localctx, 1); + { + State = 152; + _localctx.decimalnumber = Match(DEC); + } + break; + case T__8: + EnterOuterAlt(_localctx, 2); + { + State = 153; + Match(T__8); + State = 154; + _localctx.hexnumber = TokenStream.LT(1); + _la = TokenStream.LA(1); + if ( !(_la==DEC || _la==HEX) ) { + _localctx.hexnumber = ErrorHandler.RecoverInline(this); + } + else { + ErrorHandler.ReportMatch(this); + Consume(); + } + } + break; + case FLOATNUM: + EnterOuterAlt(_localctx, 3); + { + State = 155; + _localctx.floatnumber = Match(FLOATNUM); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class HexbodyContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); } + public HexbodyContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_hexbody; } } + } + + [RuleVersion(0)] + public HexbodyContext hexbody() { + HexbodyContext _localctx = new HexbodyContext(Context, State); + EnterRule(_localctx, 30, RULE_hexbody); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 158; + _la = TokenStream.LA(1); + if ( !(_la==DEC || _la==HEX) ) { + ErrorHandler.RecoverInline(this); + } + else { + ErrorHandler.ReportMatch(this); + Consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class IdContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(BdxScriptParser.ID, 0); } + public IdContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_id; } } + } + + [RuleVersion(0)] + public IdContext id() { + IdContext _localctx = new IdContext(Context, State); + EnterRule(_localctx, 32, RULE_id); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 160; + _la = TokenStream.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 360448L) != 0)) ) { + ErrorHandler.RecoverInline(this); + } + else { + ErrorHandler.ReportMatch(this); + Consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class IncludeContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode FileName() { return GetToken(BdxScriptParser.FileName, 0); } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + public IncludeContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_include; } } + } + + [RuleVersion(0)] + public IncludeContext include() { + IncludeContext _localctx = new IncludeContext(Context, State); + EnterRule(_localctx, 34, RULE_include); + try { + EnterOuterAlt(_localctx, 1); + { + State = 162; + Match(T__9); + State = 163; + Match(FileName); + State = 164; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class SectionContext : ParserRuleContext { + [System.Diagnostics.DebuggerNonUserCode] public Section_idContext section_id() { + return GetRuleContext(0); + } + [System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NL() { return GetToken(BdxScriptParser.NL, 0); } + public SectionContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_section; } } + } + + [RuleVersion(0)] + public SectionContext section() { + SectionContext _localctx = new SectionContext(Context, State); + EnterRule(_localctx, 36, RULE_section); + try { + EnterOuterAlt(_localctx, 1); + { + State = 166; + Match(T__10); + State = 167; + section_id(); + State = 168; + Match(NL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + public partial class Section_idContext : ParserRuleContext { + public Section_idContext(ParserRuleContext parent, int invokingState) + : base(parent, invokingState) + { + } + public override int RuleIndex { get { return RULE_section_id; } } + } + + [RuleVersion(0)] + public Section_idContext section_id() { + Section_idContext _localctx = new Section_idContext(Context, State); + EnterRule(_localctx, 38, RULE_section_id); + int _la; + try { + EnterOuterAlt(_localctx, 1); + { + State = 170; + _la = TokenStream.LA(1); + if ( !(_la==T__11 || _la==T__12) ) { + ErrorHandler.RecoverInline(this); + } + else { + ErrorHandler.ReportMatch(this); + Consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + ErrorHandler.ReportError(this, re); + ErrorHandler.Recover(this, re); + } + finally { + ExitRule(); + } + return _localctx; + } + + private static int[] _serializedATN = { + 4,1,22,173,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7, + 7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14, + 2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,1,0,5,0,42,8,0,10,0, + 12,0,45,9,0,1,0,1,0,5,0,49,8,0,10,0,12,0,52,9,0,5,0,54,8,0,10,0,12,0,57, + 9,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,72,8,1,1,2, + 1,2,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,4,3,4,86,8,4,1,5,1,5,1,5,1,5, + 5,5,92,8,5,10,5,12,5,95,9,5,1,5,1,5,1,6,1,6,1,6,1,6,5,6,103,8,6,10,6,12, + 6,106,9,6,1,6,1,6,1,7,1,7,1,7,3,7,113,8,7,1,7,1,7,1,8,1,8,1,8,3,8,120, + 8,8,1,8,1,8,1,9,1,9,1,9,1,9,5,9,128,8,9,10,9,12,9,131,9,9,3,9,133,8,9, + 1,9,1,9,1,10,1,10,3,10,139,8,10,1,11,1,11,1,11,1,12,1,12,1,12,3,12,147, + 8,12,1,13,1,13,3,13,151,8,13,1,14,1,14,1,14,1,14,3,14,157,8,14,1,15,1, + 15,1,16,1,16,1,17,1,17,1,17,1,17,1,18,1,18,1,18,1,18,1,19,1,19,1,19,0, + 0,20,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,0,3,1,0,15, + 16,2,0,15,16,18,18,1,0,12,13,176,0,43,1,0,0,0,2,71,1,0,0,0,4,73,1,0,0, + 0,6,75,1,0,0,0,8,85,1,0,0,0,10,87,1,0,0,0,12,98,1,0,0,0,14,109,1,0,0,0, + 16,116,1,0,0,0,18,123,1,0,0,0,20,138,1,0,0,0,22,140,1,0,0,0,24,146,1,0, + 0,0,26,150,1,0,0,0,28,156,1,0,0,0,30,158,1,0,0,0,32,160,1,0,0,0,34,162, + 1,0,0,0,36,166,1,0,0,0,38,170,1,0,0,0,40,42,5,20,0,0,41,40,1,0,0,0,42, + 45,1,0,0,0,43,41,1,0,0,0,43,44,1,0,0,0,44,55,1,0,0,0,45,43,1,0,0,0,46, + 50,3,2,1,0,47,49,5,20,0,0,48,47,1,0,0,0,49,52,1,0,0,0,50,48,1,0,0,0,50, + 51,1,0,0,0,51,54,1,0,0,0,52,50,1,0,0,0,53,46,1,0,0,0,54,57,1,0,0,0,55, + 53,1,0,0,0,55,56,1,0,0,0,56,58,1,0,0,0,57,55,1,0,0,0,58,59,5,0,0,1,59, + 1,1,0,0,0,60,72,3,36,18,0,61,72,3,6,3,0,62,63,3,4,2,0,63,64,5,1,0,0,64, + 65,5,20,0,0,65,72,1,0,0,0,66,67,3,4,2,0,67,68,5,1,0,0,68,69,3,8,4,0,69, + 72,1,0,0,0,70,72,3,8,4,0,71,60,1,0,0,0,71,61,1,0,0,0,71,62,1,0,0,0,71, + 66,1,0,0,0,71,70,1,0,0,0,72,3,1,0,0,0,73,74,3,32,16,0,74,5,1,0,0,0,75, + 76,3,32,16,0,76,77,5,2,0,0,77,78,3,28,14,0,78,7,1,0,0,0,79,86,3,12,6,0, + 80,86,3,14,7,0,81,86,3,10,5,0,82,86,3,16,8,0,83,86,3,18,9,0,84,86,3,34, + 17,0,85,79,1,0,0,0,85,80,1,0,0,0,85,81,1,0,0,0,85,82,1,0,0,0,85,83,1,0, + 0,0,85,84,1,0,0,0,86,9,1,0,0,0,87,88,5,3,0,0,88,93,3,26,13,0,89,90,5,4, + 0,0,90,92,3,26,13,0,91,89,1,0,0,0,92,95,1,0,0,0,93,91,1,0,0,0,93,94,1, + 0,0,0,94,96,1,0,0,0,95,93,1,0,0,0,96,97,5,20,0,0,97,11,1,0,0,0,98,99,5, + 5,0,0,99,104,3,24,12,0,100,101,5,4,0,0,101,103,3,24,12,0,102,100,1,0,0, + 0,103,106,1,0,0,0,104,102,1,0,0,0,104,105,1,0,0,0,105,107,1,0,0,0,106, + 104,1,0,0,0,107,108,5,20,0,0,108,13,1,0,0,0,109,112,5,6,0,0,110,113,3, + 28,14,0,111,113,3,32,16,0,112,110,1,0,0,0,112,111,1,0,0,0,113,114,1,0, + 0,0,114,115,5,20,0,0,115,15,1,0,0,0,116,119,5,7,0,0,117,120,3,28,14,0, + 118,120,3,32,16,0,119,117,1,0,0,0,119,118,1,0,0,0,120,121,1,0,0,0,121, + 122,5,20,0,0,122,17,1,0,0,0,123,132,3,32,16,0,124,129,3,20,10,0,125,126, + 5,4,0,0,126,128,3,20,10,0,127,125,1,0,0,0,128,131,1,0,0,0,129,127,1,0, + 0,0,129,130,1,0,0,0,130,133,1,0,0,0,131,129,1,0,0,0,132,124,1,0,0,0,132, + 133,1,0,0,0,133,134,1,0,0,0,134,135,5,20,0,0,135,19,1,0,0,0,136,139,3, + 28,14,0,137,139,3,32,16,0,138,136,1,0,0,0,138,137,1,0,0,0,139,21,1,0,0, + 0,140,141,5,8,0,0,141,142,3,32,16,0,142,23,1,0,0,0,143,147,3,28,14,0,144, + 147,3,32,16,0,145,147,5,14,0,0,146,143,1,0,0,0,146,144,1,0,0,0,146,145, + 1,0,0,0,147,25,1,0,0,0,148,151,3,28,14,0,149,151,3,32,16,0,150,148,1,0, + 0,0,150,149,1,0,0,0,151,27,1,0,0,0,152,157,5,15,0,0,153,154,5,9,0,0,154, + 157,7,0,0,0,155,157,5,17,0,0,156,152,1,0,0,0,156,153,1,0,0,0,156,155,1, + 0,0,0,157,29,1,0,0,0,158,159,7,0,0,0,159,31,1,0,0,0,160,161,7,1,0,0,161, + 33,1,0,0,0,162,163,5,10,0,0,163,164,5,21,0,0,164,165,5,20,0,0,165,35,1, + 0,0,0,166,167,5,11,0,0,167,168,3,38,19,0,168,169,5,20,0,0,169,37,1,0,0, + 0,170,171,7,2,0,0,171,39,1,0,0,0,15,43,50,55,71,85,93,104,112,119,129, + 132,138,146,150,156 + }; + + public static readonly ATN _ATN = + new ATNDeserializer().Deserialize(_serializedATN); + + +} diff --git a/OpenKh.Command.Bdxio/Antlr4/README.md b/OpenKh.Kh2/Bdx/Antlr/README.md similarity index 95% rename from OpenKh.Command.Bdxio/Antlr4/README.md rename to OpenKh.Kh2/Bdx/Antlr/README.md index 2c1c429ce..a7cb4b06d 100644 --- a/OpenKh.Command.Bdxio/Antlr4/README.md +++ b/OpenKh.Kh2/Bdx/Antlr/README.md @@ -1,40 +1,40 @@ -# Using Antlr4 - -Use Visual Studio Code. - -Install vscode plugin `mike-lischke.vscode-antlr4`. - -Edit `BdxScript.g4`. - -After edit, run this command: - -```bat -java.exe -jar antlr-4.11.1-complete.jar BdxScript.g4 -Dlanguage=CSharp -no-listener -no-visitor -``` - -Only `BdxScriptLexer.cs` and `BdxScriptParser.cs` are needed. Others are not needed. - -## How bdx text is parsed to tree - -Use Visual Studio Code `mike-lischke.vscode-antlr4` plugin. - -And write this at `OpenKh/OpenKh.Command.Bdxio/Antlr4/.vscode/launch.json` - -``` -{ - "version": "1.0.0", - "configurations": [ - { - "name": "Debug ANTLR4 grammar", - "type": "antlr-debug", - "request": "launch", - "input": "test.bdx", - "grammar": "BdxScript.g4", - "printParseTree": true, - "visualParseTree": true - }, - ] -} -``` - -Write something to `test.bdx` and press `F5` key. +# Using Antlr4 + +Use Visual Studio Code. + +Install vscode plugin `mike-lischke.vscode-antlr4`. + +Edit `BdxScript.g4`. + +After edit, run this command: + +```bat +java.exe -jar antlr-4.11.1-complete.jar BdxScript.g4 -Dlanguage=CSharp -no-listener -no-visitor +``` + +Only `BdxScriptLexer.cs` and `BdxScriptParser.cs` are needed. Others are not needed. + +## How bdx text is parsed to tree + +Use Visual Studio Code `mike-lischke.vscode-antlr4` plugin. + +And write this at `OpenKh/OpenKh.Command.Bdxio/Antlr4/.vscode/launch.json` + +``` +{ + "version": "1.0.0", + "configurations": [ + { + "name": "Debug ANTLR4 grammar", + "type": "antlr-debug", + "request": "launch", + "input": "test.bdx", + "grammar": "BdxScript.g4", + "printParseTree": true, + "visualParseTree": true + }, + ] +} +``` + +Write something to `test.bdx` and press `F5` key. diff --git a/OpenKh.Command.Bdxio/Models/BdxHeader.cs b/OpenKh.Kh2/Bdx/Models/BdxHeader.cs similarity index 93% rename from OpenKh.Command.Bdxio/Models/BdxHeader.cs rename to OpenKh.Kh2/Bdx/Models/BdxHeader.cs index 4a8b28f8e..9ececbaf1 100644 --- a/OpenKh.Command.Bdxio/Models/BdxHeader.cs +++ b/OpenKh.Kh2/Bdx/Models/BdxHeader.cs @@ -1,35 +1,35 @@ -using System.Text; -using Xe.BinaryMapper; -using YamlDotNet.Serialization; - -namespace OpenKh.Command.Bdxio.Models -{ - public class BdxHeader - { - [Data(Count = 16), YamlIgnore()] public byte[] RawName { get; set; } = new byte[0]; - [Data] public int WorkSize { get; set; } - [Data] public int StackSize { get; set; } - [Data] public int TempSize { get; set; } - public Trigger[] Triggers { get; set; } = new Trigger[0]; - - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool IsEmpty { get; set; } - - public string Name - { - get => Encoding.ASCII.GetString(RawName).Split('\0')[0]; - set => RawName = Encoding.ASCII.GetBytes((value ?? "").PadRight(16, '\0'), 0, 16); - } - - public class IntTrigger - { - [Data] public int Key { get; set; } - [Data] public int Addr { get; set; } - } - - public class Trigger - { - public int Key { get; set; } - public string Addr { get; set; } - } - } -} +using System.Text; +using Xe.BinaryMapper; +using YamlDotNet.Serialization; + +namespace OpenKh.Kh2.Bdx.Models +{ + public class BdxHeader + { + [Data(Count = 16), YamlIgnore()] public byte[] RawName { get; set; } = new byte[0]; + [Data] public int WorkSize { get; set; } + [Data] public int StackSize { get; set; } + [Data] public int TempSize { get; set; } + public Trigger[] Triggers { get; set; } = new Trigger[0]; + + [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool IsEmpty { get; set; } + + public string Name + { + get => Encoding.ASCII.GetString(RawName).Split('\0')[0]; + set => RawName = Encoding.ASCII.GetBytes((value ?? "").PadRight(16, '\0'), 0, 16); + } + + public class IntTrigger + { + [Data] public int Key { get; set; } + [Data] public int Addr { get; set; } + } + + public class Trigger + { + public int Key { get; set; } + public string Addr { get; set; } + } + } +} diff --git a/OpenKh.Command.Bdxio/Models/BdxInstruction.cs b/OpenKh.Kh2/Bdx/Models/BdxInstruction.cs similarity index 91% rename from OpenKh.Command.Bdxio/Models/BdxInstruction.cs rename to OpenKh.Kh2/Bdx/Models/BdxInstruction.cs index 162ee715c..f272df200 100644 --- a/OpenKh.Command.Bdxio/Models/BdxInstruction.cs +++ b/OpenKh.Kh2/Bdx/Models/BdxInstruction.cs @@ -1,32 +1,32 @@ -using OpenKh.Common.Utils; - -namespace OpenKh.Command.Bdxio.Models -{ - public class BdxInstruction - { - public ushort Code { get; set; } - - public BdxInstruction(ushort code) - { - Code = code; - } - - public byte Opcode - { - get => (byte)BitsUtil.Int.GetBits(Code, 0, 4); - set => Code = (ushort)BitsUtil.Int.SetBits(Code, 0, 4, value); - } - - public byte Sub - { - get => (byte)BitsUtil.Int.GetBits(Code, 4, 2); - set => Code = (ushort)BitsUtil.Int.SetBits(Code, 4, 2, value); - } - - public ushort Ssub - { - get => (ushort)BitsUtil.Int.GetBits(Code, 6, 12); - set => Code = (ushort)BitsUtil.Int.SetBits(Code, 6, 12, value); - } - } -} +using OpenKh.Common.Utils; + +namespace OpenKh.Kh2.Bdx.Models +{ + public class BdxInstruction + { + public ushort Code { get; set; } + + public BdxInstruction(ushort code) + { + Code = code; + } + + public byte Opcode + { + get => (byte)BitsUtil.Int.GetBits(Code, 0, 4); + set => Code = (ushort)BitsUtil.Int.SetBits(Code, 0, 4, value); + } + + public byte Sub + { + get => (byte)BitsUtil.Int.GetBits(Code, 4, 2); + set => Code = (ushort)BitsUtil.Int.SetBits(Code, 4, 2, value); + } + + public ushort Ssub + { + get => (ushort)BitsUtil.Int.GetBits(Code, 6, 12); + set => Code = (ushort)BitsUtil.Int.SetBits(Code, 6, 12, value); + } + } +} diff --git a/OpenKh.Command.Bdxio/Models/BdxInstructionDesc.cs b/OpenKh.Kh2/Bdx/Models/BdxInstructionDesc.cs similarity index 93% rename from OpenKh.Command.Bdxio/Models/BdxInstructionDesc.cs rename to OpenKh.Kh2/Bdx/Models/BdxInstructionDesc.cs index fed0781cc..42d5d4a96 100644 --- a/OpenKh.Command.Bdxio/Models/BdxInstructionDesc.cs +++ b/OpenKh.Kh2/Bdx/Models/BdxInstructionDesc.cs @@ -1,43 +1,43 @@ -namespace OpenKh.Command.Bdxio.Models -{ - public record BdxInstructionDesc - { - public ushort Code { get; set; } - public ushort CodeMask { get; set; } - - public string Name { get; set; } = ""; - public bool IsSyscall { get; set; } - public bool IsGosub { get; set; } - public bool IsJump { get; set; } - public bool IsJumpConditional { get; set; } - public bool NeverReturn { get; set; } - public bool IsGosubRet { get; set; } - public bool CodeRevealerLabeling { get; set; } - public int CodeSize { get; set; } - public Arg[] Args { get; set; } = new Arg[0]; - public string[] OldNames { get; set; } = new string[0]; - - public override string ToString() => Name; - - public record Arg - { - public string Name { get; set; } = ""; - public ArgType Type { get; set; } - - /// - /// Is relative offset to bdx instruction - /// - public bool IsRelative { get; set; } - public bool AiPos { get; set; } - public bool WorkPos { get; set; } - } - - public enum ArgType - { - Ssub, - Imm16, - Imm32, - Float32, - } - } -} +namespace OpenKh.Kh2.Bdx.Models +{ + public record BdxInstructionDesc + { + public ushort Code { get; set; } + public ushort CodeMask { get; set; } + + public string Name { get; set; } = ""; + public bool IsSyscall { get; set; } + public bool IsGosub { get; set; } + public bool IsJump { get; set; } + public bool IsJumpConditional { get; set; } + public bool NeverReturn { get; set; } + public bool IsGosubRet { get; set; } + public bool CodeRevealerLabeling { get; set; } + public int CodeSize { get; set; } + public Arg[] Args { get; set; } = new Arg[0]; + public string[] OldNames { get; set; } = new string[0]; + + public override string ToString() => Name; + + public record Arg + { + public string Name { get; set; } = ""; + public ArgType Type { get; set; } + + /// + /// Is relative offset to bdx instruction + /// + public bool IsRelative { get; set; } + public bool AiPos { get; set; } + public bool WorkPos { get; set; } + } + + public enum ArgType + { + Ssub, + Imm16, + Imm32, + Float32, + } + } +} diff --git a/OpenKh.Command.Bdxio/Models/BdxInstructionDescs.cs b/OpenKh.Kh2/Bdx/Models/BdxInstructionDescs.cs similarity index 98% rename from OpenKh.Command.Bdxio/Models/BdxInstructionDescs.cs rename to OpenKh.Kh2/Bdx/Models/BdxInstructionDescs.cs index e6b41152e..bec1a8164 100644 --- a/OpenKh.Command.Bdxio/Models/BdxInstructionDescs.cs +++ b/OpenKh.Kh2/Bdx/Models/BdxInstructionDescs.cs @@ -1,95 +1,97 @@ -using static OpenKh.Command.Bdxio.Models.BdxInstructionDesc; - -namespace OpenKh.Command.Bdxio.Models -{ - public class BdxInstructionDescs - { - public static IEnumerable GetDescs() => _descs; - - public static BdxInstructionDesc? FindByCode(ushort code) - { - return _descs - .FirstOrDefault(it => (code & it.CodeMask) == it.Code); - } - - private static readonly BdxInstructionDesc[] _descs = new[] - { - #region Generated - - new BdxInstructionDesc { Code = 0x0000, CodeMask = 0x003F, Name = "push", CodeRevealerLabeling = true, CodeSize = 3, Args = new[] { new Arg { Name = "imm32", Type = ArgType.Imm32 } }, OldNames = new[] { "pushImm" } }, - new BdxInstructionDesc { Code = 0x0010, CodeMask = 0x003F, Name = "push.s", CodeSize = 3, Args = new[] { new Arg { Name = "float32", Type = ArgType.Float32 } }, OldNames = new[] { "pushImmf" } }, - new BdxInstructionDesc { Code = 0x0020, CodeMask = 0xFFFF, Name = "push.sp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromPSp" } }, - new BdxInstructionDesc { Code = 0x0060, CodeMask = 0xFFFF, Name = "push.wp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "pushFromPWp" } }, - new BdxInstructionDesc { Code = 0x00A0, CodeMask = 0xFFFF, Name = "push.sp.d", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromPSpVal" } }, - new BdxInstructionDesc { Code = 0x00E0, CodeMask = 0xFFFF, Name = "push.bd", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "pushFromPAi" } }, - new BdxInstructionDesc { Code = 0x0030, CodeMask = 0xFFFF, Name = "push.d.sp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromFSp" } }, - new BdxInstructionDesc { Code = 0x0070, CodeMask = 0xFFFF, Name = "push.d.wp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "pushFromFWp" } }, - new BdxInstructionDesc { Code = 0x00B0, CodeMask = 0xFFFF, Name = "push.d.sp.d", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromFSpVal" } }, - new BdxInstructionDesc { Code = 0x00F0, CodeMask = 0xFFFF, Name = "push.d.bd", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "pushFromFAi" } }, - new BdxInstructionDesc { Code = 0x0001, CodeMask = 0xFFCF, Name = "pop.sp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "popToSp" } }, - new BdxInstructionDesc { Code = 0x0041, CodeMask = 0xFFCF, Name = "pop.wp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "popToWp" } }, - new BdxInstructionDesc { Code = 0x0081, CodeMask = 0xFFCF, Name = "pop.sp.d", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "popToSpVal" } }, - new BdxInstructionDesc { Code = 0x00C1, CodeMask = 0xFFCF, Name = "pop.bd", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "popToAi" } }, - new BdxInstructionDesc { Code = 0x0002, CodeMask = 0xFFCF, Name = "memcpy.sp", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16 } }, OldNames = new[] { "memcpyToSp" } }, - new BdxInstructionDesc { Code = 0x0042, CodeMask = 0xFFCF, Name = "memcpy.wp", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "memcpyToWp" } }, - new BdxInstructionDesc { Code = 0x0082, CodeMask = 0xFFCF, Name = "memcpy.sp.d", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16 } }, OldNames = new[] { "memcpyToSpVal" } }, - new BdxInstructionDesc { Code = 0x00C2, CodeMask = 0xFFCF, Name = "memcpy.bd", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "memcpyToSpAi" } }, - new BdxInstructionDesc { Code = 0x0003, CodeMask = 0x000F, Name = "push.d.pop", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "fetchValue" } }, - new BdxInstructionDesc { Code = 0x0004, CodeMask = 0x000F, Name = "memcpy", CodeSize = 1, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub } } }, - new BdxInstructionDesc { Code = 0x0005, CodeMask = 0xFFFF, Name = "cvt.w.s", CodeSize = 1, OldNames = new[] { "citf" } }, - new BdxInstructionDesc { Code = 0x0085, CodeMask = 0xFFFF, Name = "neg", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x00C5, CodeMask = 0xFFFF, Name = "not", CodeSize = 1, OldNames = new[] { "inv" } }, - new BdxInstructionDesc { Code = 0x0105, CodeMask = 0xFFFF, Name = "seqz", CodeSize = 1, OldNames = new[] { "eqz" } }, - new BdxInstructionDesc { Code = 0x0145, CodeMask = 0xFFFF, Name = "abs", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0185, CodeMask = 0xFFFF, Name = "sltz", CodeSize = 1, OldNames = new[] { "msb" } }, - new BdxInstructionDesc { Code = 0x01C5, CodeMask = 0xFFFF, Name = "slez", CodeSize = 1, OldNames = new[] { "info" } }, - new BdxInstructionDesc { Code = 0x0205, CodeMask = 0xFFFF, Name = "seqz", CodeSize = 1, OldNames = new[] { "eqz" } }, - new BdxInstructionDesc { Code = 0x0245, CodeMask = 0xFFFF, Name = "snez", CodeSize = 1, OldNames = new[] { "neqz" } }, - new BdxInstructionDesc { Code = 0x0285, CodeMask = 0xFFFF, Name = "sgez", CodeSize = 1, OldNames = new[] { "msbi" } }, - new BdxInstructionDesc { Code = 0x02C5, CodeMask = 0xFFFF, Name = "sgtz", CodeSize = 1, OldNames = new[] { "ipos" } }, - new BdxInstructionDesc { Code = 0x0055, CodeMask = 0xFFFF, Name = "cvt.s.w", CodeSize = 1, OldNames = new[] { "cfti" } }, - new BdxInstructionDesc { Code = 0x0095, CodeMask = 0xFFFF, Name = "neg.s", CodeSize = 1, OldNames = new[] { "negf" } }, - new BdxInstructionDesc { Code = 0x0155, CodeMask = 0xFFFF, Name = "abs.s", CodeSize = 1, OldNames = new[] { "absf" } }, - new BdxInstructionDesc { Code = 0x0195, CodeMask = 0xFFFF, Name = "sltz.s", CodeSize = 1, OldNames = new[] { "infzf" } }, - new BdxInstructionDesc { Code = 0x01D5, CodeMask = 0xFFFF, Name = "slez.s", CodeSize = 1, OldNames = new[] { "infoezf" } }, - new BdxInstructionDesc { Code = 0x0215, CodeMask = 0xFFFF, Name = "seqz.s", CodeSize = 1, OldNames = new[] { "eqzf" } }, - new BdxInstructionDesc { Code = 0x0255, CodeMask = 0xFFFF, Name = "snez.s", CodeSize = 1, OldNames = new[] { "neqzf" } }, - new BdxInstructionDesc { Code = 0x0295, CodeMask = 0xFFFF, Name = "sgez.s", CodeSize = 1, OldNames = new[] { "supoezf" } }, - new BdxInstructionDesc { Code = 0x02D5, CodeMask = 0xFFFF, Name = "sgtz.s", CodeSize = 1, OldNames = new[] { "supzf" } }, - new BdxInstructionDesc { Code = 0x0006, CodeMask = 0xFFFF, Name = "add", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0046, CodeMask = 0xFFFF, Name = "sub", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0086, CodeMask = 0xFFFF, Name = "mul", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x00C6, CodeMask = 0xFFFF, Name = "div", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0106, CodeMask = 0xFFFF, Name = "mod", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0146, CodeMask = 0xFFFF, Name = "and", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0186, CodeMask = 0xFFFF, Name = "or", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x01C6, CodeMask = 0xFFFF, Name = "xor", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0206, CodeMask = 0xFFFF, Name = "sll", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0246, CodeMask = 0xFFFF, Name = "sra", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0286, CodeMask = 0xFFFF, Name = "land", CodeSize = 1, OldNames = new[] { "eqzv" } }, - new BdxInstructionDesc { Code = 0x02C6, CodeMask = 0xFFFF, Name = "lor", CodeSize = 1, OldNames = new[] { "neqzv" } }, - new BdxInstructionDesc { Code = 0x0016, CodeMask = 0xFFFF, Name = "add.s", CodeSize = 1, OldNames = new[] { "addf" } }, - new BdxInstructionDesc { Code = 0x0056, CodeMask = 0xFFFF, Name = "sub.s", CodeSize = 1, OldNames = new[] { "subf" } }, - new BdxInstructionDesc { Code = 0x0096, CodeMask = 0xFFFF, Name = "mul.s", CodeSize = 1, OldNames = new[] { "mulf" } }, - new BdxInstructionDesc { Code = 0x00D6, CodeMask = 0xFFFF, Name = "div.s", CodeSize = 1, OldNames = new[] { "divf" } }, - new BdxInstructionDesc { Code = 0x0116, CodeMask = 0xFFFF, Name = "mod.s", CodeSize = 1, OldNames = new[] { "modf" } }, - new BdxInstructionDesc { Code = 0x0007, CodeMask = 0xFFCF, Name = "b", IsJump = true, CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "jmp" } }, - new BdxInstructionDesc { Code = 0x0047, CodeMask = 0xFFCF, Name = "beqz", IsJump = true, IsJumpConditional = true, CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "jz" } }, - new BdxInstructionDesc { Code = 0x0087, CodeMask = 0xFFCF, Name = "bnez", IsJump = true, IsJumpConditional = true, CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "jnz" } }, - new BdxInstructionDesc { Code = 0x0008, CodeMask = 0x000F, Name = "jal", IsGosub = true, CodeSize = 2, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub }, new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "gosub" } }, - new BdxInstructionDesc { Code = 0x0009, CodeMask = 0xFFCF, Name = "halt", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0049, CodeMask = 0xFFCF, Name = "exit", NeverReturn = true, CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0089, CodeMask = 0xFFCF, Name = "ret", IsGosubRet = true, CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x00C9, CodeMask = 0xFFCF, Name = "drop", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0149, CodeMask = 0xFFCF, Name = "dup", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0189, CodeMask = 0xFFCF, Name = "sin", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x01C9, CodeMask = 0xFFCF, Name = "cos", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0209, CodeMask = 0xFFCF, Name = "degr", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x0249, CodeMask = 0xFFCF, Name = "radd", CodeSize = 1 }, - new BdxInstructionDesc { Code = 0x000A, CodeMask = 0x000F, Name = "syscall", IsSyscall = true, CodeSize = 2, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub }, new Arg { Name = "imm16", Type = ArgType.Imm16 } } }, - new BdxInstructionDesc { Code = 0x000B, CodeMask = 0x000F, Name = "jal32", IsGosub = true, CodeSize = 3, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub }, new Arg { Name = "imm32", Type = ArgType.Imm32, IsRelative = true } }, OldNames = new[] { "gosub32" } }, - - #endregion - }; - } -} +using System.Collections.Generic; +using System.Linq; +using static OpenKh.Kh2.Bdx.Models.BdxInstructionDesc; + +namespace OpenKh.Kh2.Bdx.Models +{ + public class BdxInstructionDescs + { + public static IEnumerable GetDescs() => _descs; + + public static BdxInstructionDesc? FindByCode(ushort code) + { + return _descs + .FirstOrDefault(it => (code & it.CodeMask) == it.Code); + } + + private static readonly BdxInstructionDesc[] _descs = new[] + { + #region Generated + + new BdxInstructionDesc { Code = 0x0000, CodeMask = 0x003F, Name = "push", CodeRevealerLabeling = true, CodeSize = 3, Args = new[] { new Arg { Name = "imm32", Type = ArgType.Imm32 } }, OldNames = new[] { "pushImm" } }, + new BdxInstructionDesc { Code = 0x0010, CodeMask = 0x003F, Name = "push.s", CodeSize = 3, Args = new[] { new Arg { Name = "float32", Type = ArgType.Float32 } }, OldNames = new[] { "pushImmf" } }, + new BdxInstructionDesc { Code = 0x0020, CodeMask = 0xFFFF, Name = "push.sp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromPSp" } }, + new BdxInstructionDesc { Code = 0x0060, CodeMask = 0xFFFF, Name = "push.wp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "pushFromPWp" } }, + new BdxInstructionDesc { Code = 0x00A0, CodeMask = 0xFFFF, Name = "push.sp.d", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromPSpVal" } }, + new BdxInstructionDesc { Code = 0x00E0, CodeMask = 0xFFFF, Name = "push.bd", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "pushFromPAi" } }, + new BdxInstructionDesc { Code = 0x0030, CodeMask = 0xFFFF, Name = "push.d.sp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromFSp" } }, + new BdxInstructionDesc { Code = 0x0070, CodeMask = 0xFFFF, Name = "push.d.wp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "pushFromFWp" } }, + new BdxInstructionDesc { Code = 0x00B0, CodeMask = 0xFFFF, Name = "push.d.sp.d", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "pushFromFSpVal" } }, + new BdxInstructionDesc { Code = 0x00F0, CodeMask = 0xFFFF, Name = "push.d.bd", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "pushFromFAi" } }, + new BdxInstructionDesc { Code = 0x0001, CodeMask = 0xFFCF, Name = "pop.sp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "popToSp" } }, + new BdxInstructionDesc { Code = 0x0041, CodeMask = 0xFFCF, Name = "pop.wp", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "popToWp" } }, + new BdxInstructionDesc { Code = 0x0081, CodeMask = 0xFFCF, Name = "pop.sp.d", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "popToSpVal" } }, + new BdxInstructionDesc { Code = 0x00C1, CodeMask = 0xFFCF, Name = "pop.bd", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "popToAi" } }, + new BdxInstructionDesc { Code = 0x0002, CodeMask = 0xFFCF, Name = "memcpy.sp", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16 } }, OldNames = new[] { "memcpyToSp" } }, + new BdxInstructionDesc { Code = 0x0042, CodeMask = 0xFFCF, Name = "memcpy.wp", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16, WorkPos = true } }, OldNames = new[] { "memcpyToWp" } }, + new BdxInstructionDesc { Code = 0x0082, CodeMask = 0xFFCF, Name = "memcpy.sp.d", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16 } }, OldNames = new[] { "memcpyToSpVal" } }, + new BdxInstructionDesc { Code = 0x00C2, CodeMask = 0xFFCF, Name = "memcpy.bd", CodeSize = 3, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 }, new Arg { Name = "imm16_2", Type = ArgType.Imm16, AiPos = true } }, OldNames = new[] { "memcpyToSpAi" } }, + new BdxInstructionDesc { Code = 0x0003, CodeMask = 0x000F, Name = "push.d.pop", CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16 } }, OldNames = new[] { "fetchValue" } }, + new BdxInstructionDesc { Code = 0x0004, CodeMask = 0x000F, Name = "memcpy", CodeSize = 1, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub } } }, + new BdxInstructionDesc { Code = 0x0005, CodeMask = 0xFFFF, Name = "cvt.w.s", CodeSize = 1, OldNames = new[] { "citf" } }, + new BdxInstructionDesc { Code = 0x0085, CodeMask = 0xFFFF, Name = "neg", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x00C5, CodeMask = 0xFFFF, Name = "not", CodeSize = 1, OldNames = new[] { "inv" } }, + new BdxInstructionDesc { Code = 0x0105, CodeMask = 0xFFFF, Name = "seqz", CodeSize = 1, OldNames = new[] { "eqz" } }, + new BdxInstructionDesc { Code = 0x0145, CodeMask = 0xFFFF, Name = "abs", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0185, CodeMask = 0xFFFF, Name = "sltz", CodeSize = 1, OldNames = new[] { "msb" } }, + new BdxInstructionDesc { Code = 0x01C5, CodeMask = 0xFFFF, Name = "slez", CodeSize = 1, OldNames = new[] { "info" } }, + new BdxInstructionDesc { Code = 0x0205, CodeMask = 0xFFFF, Name = "seqz", CodeSize = 1, OldNames = new[] { "eqz" } }, + new BdxInstructionDesc { Code = 0x0245, CodeMask = 0xFFFF, Name = "snez", CodeSize = 1, OldNames = new[] { "neqz" } }, + new BdxInstructionDesc { Code = 0x0285, CodeMask = 0xFFFF, Name = "sgez", CodeSize = 1, OldNames = new[] { "msbi" } }, + new BdxInstructionDesc { Code = 0x02C5, CodeMask = 0xFFFF, Name = "sgtz", CodeSize = 1, OldNames = new[] { "ipos" } }, + new BdxInstructionDesc { Code = 0x0055, CodeMask = 0xFFFF, Name = "cvt.s.w", CodeSize = 1, OldNames = new[] { "cfti" } }, + new BdxInstructionDesc { Code = 0x0095, CodeMask = 0xFFFF, Name = "neg.s", CodeSize = 1, OldNames = new[] { "negf" } }, + new BdxInstructionDesc { Code = 0x0155, CodeMask = 0xFFFF, Name = "abs.s", CodeSize = 1, OldNames = new[] { "absf" } }, + new BdxInstructionDesc { Code = 0x0195, CodeMask = 0xFFFF, Name = "sltz.s", CodeSize = 1, OldNames = new[] { "infzf" } }, + new BdxInstructionDesc { Code = 0x01D5, CodeMask = 0xFFFF, Name = "slez.s", CodeSize = 1, OldNames = new[] { "infoezf" } }, + new BdxInstructionDesc { Code = 0x0215, CodeMask = 0xFFFF, Name = "seqz.s", CodeSize = 1, OldNames = new[] { "eqzf" } }, + new BdxInstructionDesc { Code = 0x0255, CodeMask = 0xFFFF, Name = "snez.s", CodeSize = 1, OldNames = new[] { "neqzf" } }, + new BdxInstructionDesc { Code = 0x0295, CodeMask = 0xFFFF, Name = "sgez.s", CodeSize = 1, OldNames = new[] { "supoezf" } }, + new BdxInstructionDesc { Code = 0x02D5, CodeMask = 0xFFFF, Name = "sgtz.s", CodeSize = 1, OldNames = new[] { "supzf" } }, + new BdxInstructionDesc { Code = 0x0006, CodeMask = 0xFFFF, Name = "add", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0046, CodeMask = 0xFFFF, Name = "sub", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0086, CodeMask = 0xFFFF, Name = "mul", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x00C6, CodeMask = 0xFFFF, Name = "div", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0106, CodeMask = 0xFFFF, Name = "mod", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0146, CodeMask = 0xFFFF, Name = "and", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0186, CodeMask = 0xFFFF, Name = "or", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x01C6, CodeMask = 0xFFFF, Name = "xor", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0206, CodeMask = 0xFFFF, Name = "sll", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0246, CodeMask = 0xFFFF, Name = "sra", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0286, CodeMask = 0xFFFF, Name = "land", CodeSize = 1, OldNames = new[] { "eqzv" } }, + new BdxInstructionDesc { Code = 0x02C6, CodeMask = 0xFFFF, Name = "lor", CodeSize = 1, OldNames = new[] { "neqzv" } }, + new BdxInstructionDesc { Code = 0x0016, CodeMask = 0xFFFF, Name = "add.s", CodeSize = 1, OldNames = new[] { "addf" } }, + new BdxInstructionDesc { Code = 0x0056, CodeMask = 0xFFFF, Name = "sub.s", CodeSize = 1, OldNames = new[] { "subf" } }, + new BdxInstructionDesc { Code = 0x0096, CodeMask = 0xFFFF, Name = "mul.s", CodeSize = 1, OldNames = new[] { "mulf" } }, + new BdxInstructionDesc { Code = 0x00D6, CodeMask = 0xFFFF, Name = "div.s", CodeSize = 1, OldNames = new[] { "divf" } }, + new BdxInstructionDesc { Code = 0x0116, CodeMask = 0xFFFF, Name = "mod.s", CodeSize = 1, OldNames = new[] { "modf" } }, + new BdxInstructionDesc { Code = 0x0007, CodeMask = 0xFFCF, Name = "b", IsJump = true, CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "jmp" } }, + new BdxInstructionDesc { Code = 0x0047, CodeMask = 0xFFCF, Name = "beqz", IsJump = true, IsJumpConditional = true, CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "jz" } }, + new BdxInstructionDesc { Code = 0x0087, CodeMask = 0xFFCF, Name = "bnez", IsJump = true, IsJumpConditional = true, CodeSize = 2, Args = new[] { new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "jnz" } }, + new BdxInstructionDesc { Code = 0x0008, CodeMask = 0x000F, Name = "jal", IsGosub = true, CodeSize = 2, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub }, new Arg { Name = "imm16", Type = ArgType.Imm16, IsRelative = true } }, OldNames = new[] { "gosub" } }, + new BdxInstructionDesc { Code = 0x0009, CodeMask = 0xFFCF, Name = "halt", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0049, CodeMask = 0xFFCF, Name = "exit", NeverReturn = true, CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0089, CodeMask = 0xFFCF, Name = "ret", IsGosubRet = true, CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x00C9, CodeMask = 0xFFCF, Name = "drop", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0149, CodeMask = 0xFFCF, Name = "dup", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0189, CodeMask = 0xFFCF, Name = "sin", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x01C9, CodeMask = 0xFFCF, Name = "cos", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0209, CodeMask = 0xFFCF, Name = "degr", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x0249, CodeMask = 0xFFCF, Name = "radd", CodeSize = 1 }, + new BdxInstructionDesc { Code = 0x000A, CodeMask = 0x000F, Name = "syscall", IsSyscall = true, CodeSize = 2, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub }, new Arg { Name = "imm16", Type = ArgType.Imm16 } } }, + new BdxInstructionDesc { Code = 0x000B, CodeMask = 0x000F, Name = "jal32", IsGosub = true, CodeSize = 3, Args = new[] { new Arg { Name = "ssub", Type = ArgType.Ssub }, new Arg { Name = "imm32", Type = ArgType.Imm32, IsRelative = true } }, OldNames = new[] { "gosub32" } }, + + #endregion + }; + } +} diff --git a/OpenKh.Command.Bdxio/Models/BdxTrap.cs b/OpenKh.Kh2/Bdx/Models/BdxTrap.cs similarity index 81% rename from OpenKh.Command.Bdxio/Models/BdxTrap.cs rename to OpenKh.Kh2/Bdx/Models/BdxTrap.cs index b44a23d28..4f9851063 100644 --- a/OpenKh.Command.Bdxio/Models/BdxTrap.cs +++ b/OpenKh.Kh2/Bdx/Models/BdxTrap.cs @@ -1,10 +1,10 @@ -namespace OpenKh.Command.Bdxio.Models -{ - public class BdxTrap - { - public int TableIndex { get; set; } - public int TrapIndex { get; set; } - public string Name { get; set; } - public int Flags { get; set; } - } -} +namespace OpenKh.Kh2.Bdx.Models +{ + public class BdxTrap + { + public int TableIndex { get; set; } + public int TrapIndex { get; set; } + public string Name { get; set; } + public int Flags { get; set; } + } +} diff --git a/OpenKh.Command.Bdxio/Models/BdxTraps.cs b/OpenKh.Kh2/Bdx/Models/BdxTraps.cs similarity index 99% rename from OpenKh.Command.Bdxio/Models/BdxTraps.cs rename to OpenKh.Kh2/Bdx/Models/BdxTraps.cs index 51a55a3db..f4e8baecf 100644 --- a/OpenKh.Command.Bdxio/Models/BdxTraps.cs +++ b/OpenKh.Kh2/Bdx/Models/BdxTraps.cs @@ -1,843 +1,845 @@ -namespace OpenKh.Command.Bdxio.Models -{ - public class BdxTraps - { - public static IEnumerable GetTraps() => _traps; - - private static readonly BdxTrap[] _traps = new[] - { - #region Generated - - new BdxTrap { TableIndex = 0, TrapIndex = 0, Name = "trap_puti", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 1, Name = "trap_putf", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 2, Name = "trap_puts", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 3, Name = "trap_frametime", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 4, Name = "trap_vector_add", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 5, Name = "trap_vector_sub", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 6, Name = "trap_vector_len", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 7, Name = "trap_vector_normalize", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 8, Name = "trap_vector_dump", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 9, Name = "trap_thread_start", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 0, TrapIndex = 11, Name = "trap_file_is_reading", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 12, Name = "trap_file_flush", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 13, Name = "trap_vector_roty", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 14, Name = "trap_progress_set_flag", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 15, Name = "trap_progress_check_flag", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 16, Name = "trap_random_get", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 17, Name = "trap_random_getf", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 18, Name = "trap_random_range", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 19, Name = "trap_worldflag_set", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 20, Name = "trap_worldflag_check", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 21, Name = "trap_vector_get_rot_xz", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 22, Name = "trap_abs", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 23, Name = "trap_absf", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 24, Name = "trap_stputi", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 25, Name = "trap_stputf", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 26, Name = "trap_stputs", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 27, Name = "func_system_set_game_speed", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 28, Name = "method_blur_init", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 29, Name = "method_blur_start", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 30, Name = "method_blur_stop", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 31, Name = "func_screen_whiteout", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 32, Name = "func_screen_whitein", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 35, Name = "method_vector_scale", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 36, Name = "trap_vector_mul", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 37, Name = "trap_vector_div", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 38, Name = "trap_effect_set_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 39, Name = "trap_effect_set_scale", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 40, Name = "trap_effect_set_rot", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 41, Name = "trap_effect_set_dir", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 42, Name = "trap_vector_atan_xz", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 43, Name = "trap_fixrad", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 44, Name = "trap_effect_loop_end", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 45, Name = "trap_vector_addf", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 46, Name = "trap_vector_homing", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 47, Name = "trap_memory_alloc", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 48, Name = "trap_memory_free", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 49, Name = "trap_effect_is_alive", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 50, Name = "trap_effect_is_active", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 51, Name = "trap_effect_kill", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 52, Name = "trap_effect_fadeout", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 53, Name = "trap_effect_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 54, Name = "trap_effect_dir", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 55, Name = "trap_timer_count_down", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 56, Name = "trap_timer_count_up", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 57, Name = "trap_saveflag_set", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 58, Name = "trap_saveflag_reset", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 59, Name = "trap_saveflag_check", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 60, Name = "trap_assert", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 61, Name = "trap_saveram_get_partram", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 62, Name = "trap_partram_set_item_max", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 63, Name = "trap_item_get", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 64, Name = "trap_sound_disable", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 65, Name = "trap_sound_play_system", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 66, Name = "trap_effect_pause", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 67, Name = "trap_effect_set_color", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 68, Name = "trap_vector_rotx", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 69, Name = "trap_menuflag_set", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 70, Name = "trap_progress_is_second", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 73, Name = "trap_menuflag_reset", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 74, Name = "trap_screen_show_picture", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 75, Name = "trap_saveram_set_weapon", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 76, Name = "trap_saveram_set_form_weapon", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 77, Name = "trap_screen_cross_fade", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 78, Name = "trap_vector_inter", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 79, Name = "trap_effect_add_dead_block", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 80, Name = "trap_pad_is_button", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 81, Name = "trap_pad_is_trigger", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 82, Name = "trap_vector_outer_product", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 83, Name = "trap_vector_rot", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 84, Name = "trap_vector_angle", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 85, Name = "trap_effect_loop_end_kill", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 86, Name = "trap_effect_set_type", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 87, Name = "trap_screen_fadeout", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 88, Name = "trap_screen_fadein", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 89, Name = "trap_menuflag_check", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 90, Name = "trap_vector_draw", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 0, TrapIndex = 91, Name = "trap_vector_inner_prodcut", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 92, Name = "trap_partram_add_attack", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 93, Name = "trap_partram_add_wisdom", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 94, Name = "trap_partram_add_defence", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 95, Name = "trap_partram_set_levelup_type", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 96, Name = "trap_partram_add_ap", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 97, Name = "trap_item_reduce", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 98, Name = "trap_saveram_set_form_ability", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 0, TrapIndex = 99, Name = "trap_partram_add_ability", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 0, TrapIndex = 100, Name = "trap_saveram_increment_friend_recov", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 101, Name = "trap_progress_is_secret_movie", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 102, Name = "trap_vector_to_angle", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 0, TrapIndex = 103, Name = "trap_progress_is_fm_secret_movie", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 0, TrapIndex = 104, Name = "trap_sound_set_bgse_volume", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 0, Name = "trap_sysobj_appear", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 1, Name = "trap_obj_set_rot", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 2, Name = "trap_sysobj_moveto", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 3, Name = "trap_sysobj_player", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 4, Name = "trap_obj_wish_dir", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 5, Name = "trap_act_table_init", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 6, Name = "trap_act_table_add", Flags = 0x0000000C }, - new BdxTrap { TableIndex = 1, TrapIndex = 7, Name = "trap_obj_set_act_table", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 8, Name = "trap_obj_act_start", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 9, Name = "trap_obj_act_push", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 10, Name = "trap_obj_is_act_exec", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 11, Name = "trap_sysobj_motion_start", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 12, Name = "trap_sysobj_motion_change", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 13, Name = "trap_sysobj_motion_push", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 14, Name = "trap_sysobj_motion_is_end", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 15, Name = "trap_sysobj_motion_id", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 17, Name = "trap_obj_leave_force", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 18, Name = "trap_obj_attach", Flags = 0x00000006 }, - new BdxTrap { TableIndex = 1, TrapIndex = 19, Name = "trap_sysobj_fadeout", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 20, Name = "trap_sysobj_fadein", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 21, Name = "trap_obj_effect_start", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 22, Name = "trap_obj_effect_start_pos", Flags = 0x40000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 23, Name = "trap_area_world", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 24, Name = "trap_area_area", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 25, Name = "trap_area_map_set", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 26, Name = "trap_area_battle_set", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 27, Name = "trap_area_event_set", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 28, Name = "trap_obj_leave", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 29, Name = "trap_obj_motion_capture", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 30, Name = "trap_area_jump", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 31, Name = "trap_area_setjump", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 32, Name = "trap_message_open", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 33, Name = "trap_message_close", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 34, Name = "trap_event_is_exec", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 35, Name = "trap_area_init", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 36, Name = "trap_bg_hide", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 37, Name = "trap_bg_show", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 38, Name = "trap_obj_set_team", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 39, Name = "trap_obj_unit_arg", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 40, Name = "trap_obj_is_pirate_shade", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 41, Name = "trap_signal_call", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 42, Name = "func_obj_control_off", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 43, Name = "func_obj_control_on", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 44, Name = "func_history_clear_enemy", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 45, Name = "func_area_activate_unit", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 46, Name = "func_bg_barrier_on", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 47, Name = "func_bg_barrier_off", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 48, Name = "method_message_is_end", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 49, Name = "method_obj_enable_reaction_command", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 50, Name = "method_obj_disable_reaction_command", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 51, Name = "method_obj_reset_reaction_command", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 52, Name = "method_obj_enable_collision", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 53, Name = "method_obj_disable_collision", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 54, Name = "method_obj_reset_collision", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 55, Name = "method_obj_jump", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 56, Name = "method_obj_is_culling", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 57, Name = "trap_obj_is_jump", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 58, Name = "trap_obj_fly", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 59, Name = "trap_obj_is_fly", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 60, Name = "trap_obj_is_air", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 61, Name = "trap_sysobj_motion_frame_start", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 62, Name = "trap_obj_get_moved", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 63, Name = "trap_obj_is_motion_in_loop", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 64, Name = "trap_obj_get_wish_movement", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 65, Name = "trap_obj_exec_fall", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 66, Name = "trap_obj_exec_land", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 67, Name = "trap_obj_motion_get_length", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 68, Name = "trap_obj_motion_get_loop_top", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 69, Name = "trap_obj_motion_get_time", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 70, Name = "trap_obj_set_flag", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 71, Name = "trap_obj_reset_flag", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 72, Name = "trap_obj_check_flag", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 73, Name = "trap_obj_hover", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 74, Name = "trap_obj_idle", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 75, Name = "trap_obj_motion_hook", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 76, Name = "trap_obj_motion_unhook", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 77, Name = "trap_obj_motion_is_hook", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 78, Name = "trap_obj_motion_is_no_control", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 79, Name = "trap_obj_set_dir", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 80, Name = "trap_obj_turn_dir", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 81, Name = "trap_obj_act_wedge", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 82, Name = "trap_obj_thread_start", Flags = 0x40000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 83, Name = "trap_obj_apply_bone_matrix", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 84, Name = "trap_obj_sheet", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 85, Name = "trap_obj_texanm_start", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 86, Name = "trap_obj_texanm_stop", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 87, Name = "trap_obj_effect_start_bind", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 88, Name = "trap_obj_target_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 89, Name = "trap_obj_move_request", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 90, Name = "trap_obj_act_shout", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 91, Name = "trap_obj_star", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 92, Name = "trap_obj_scatter_prize", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 93, Name = "trap_sysobj_party", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 94, Name = "trap_sysobj_is_exist", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 95, Name = "trap_obj_fly_to_jump", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 96, Name = "trap_obj_get_action", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 97, Name = "trap_obj_spec", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 98, Name = "trap_obj_step_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 99, Name = "trap_obj_float_height", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 100, Name = "trap_obj_jump_height_to_uptime", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 101, Name = "trap_obj_motion_is_capture", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 102, Name = "trap_obj_detach", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 103, Name = "trap_obj_set_detach_callback", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 104, Name = "trap_obj_shadow_move_start", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 105, Name = "trap_obj_shadow_move_end", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 106, Name = "trap_signal_reserve_hp", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 107, Name = "trap_obj_motion_speed", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 108, Name = "trap_obj_show_part", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 109, Name = "trap_obj_hide_part", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 110, Name = "trap_obj_get_appear_way", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 111, Name = "trap_obj_set_movement", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 112, Name = "trap_obj_hook", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 113, Name = "trap_player_get_movement", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 114, Name = "trap_obj_search_by_entry", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 115, Name = "trap_obj_set_jump_motion", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 117, Name = "trap_command_cage_on", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 118, Name = "trap_command_cage_off", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 119, Name = "trap_obj_check_step", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 120, Name = "trap_target_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 121, Name = "trap_target_search", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 122, Name = "trap_obj_dump", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 123, Name = "trap_obj_tex_fade_set", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 124, Name = "trap_obj_is_entry_fly", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 125, Name = "trap_obj_tex_fade_start", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 126, Name = "trap_obj_motion_sync", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 127, Name = "trap_obj_act_clear", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 128, Name = "trap_obj_sysjump", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 129, Name = "trap_obj_blow", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 130, Name = "trap_obj_cmp", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 131, Name = "trap_target_dup", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 132, Name = "trap_target_free", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 133, Name = "trap_obj_hide", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 134, Name = "trap_obj_show", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 135, Name = "trap_bg_cross_pos", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 136, Name = "trap_bg_is_floor", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 137, Name = "trap_bg_get_normal", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 138, Name = "trap_pax_start", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 139, Name = "trap_pax_start_bind", Flags = 0x40000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 140, Name = "trap_target_is_exist", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 141, Name = "trap_bg_ground_pos", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 142, Name = "trap_signal_reserve_min_hp", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 143, Name = "trap_obj_search_by_serial", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 144, Name = "trap_obj_serial", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 145, Name = "trap_obj_touch_zone", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 146, Name = "trap_obj_hitback", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 147, Name = "trap_obj_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 148, Name = "trap_obj_set_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 149, Name = "trap_obj_effect_start_bind_other", Flags = 0x40000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 150, Name = "trap_obj_motion_check_range", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 151, Name = "trap_obj_motion_check_trigger", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 152, Name = "trap_status_is_mission", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 153, Name = "trap_obj_reset_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 154, Name = "trap_status_secure_mode_start", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 155, Name = "trap_obj_add_hp", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 156, Name = "trap_obj_hop", Flags = 0x00000007 }, - new BdxTrap { TableIndex = 1, TrapIndex = 157, Name = "trap_obj_camera_start", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 158, Name = "trap_bg_set_belt_conveyor", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 159, Name = "trap_bg_set_uvscroll_speed", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 160, Name = "trap_target_set_obj", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 161, Name = "trap_obj_is_attach", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 162, Name = "trap_target_set_before_player", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 163, Name = "trap_target_set_after_player", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 164, Name = "trap_obj_camera_start_global", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 165, Name = "trap_command_override", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 166, Name = "trap_target_attack", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 167, Name = "trap_obj_act_start_pri", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 168, Name = "trap_obj_flyjump", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 169, Name = "trap_obj_effect_unbind", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 170, Name = "trap_obj_unit_group", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 171, Name = "trap_status_no_leave", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 172, Name = "trap_obj_can_look", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 173, Name = "trap_obj_can_look_pos", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 174, Name = "trap_obj_look_start", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 175, Name = "trap_obj_look_start_pos", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 176, Name = "trap_obj_look_end", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 177, Name = "trap_obj_set_path", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 178, Name = "trap_obj_get_path_movement", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 179, Name = "trap_obj_set_fall_motion", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 180, Name = "trap_obj_set_land_motion", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 181, Name = "trap_light_create", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 182, Name = "trap_light_set_flag", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 183, Name = "trap_light_set_color", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 184, Name = "trap_light_fadeout", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 185, Name = "trap_obj_set_parts_color", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 186, Name = "trap_obj_reset_parts_color", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 187, Name = "trap_status_prize_drain_start", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 188, Name = "trap_status_prize_drain_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 189, Name = "trap_obj_history_mark", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 190, Name = "trap_obj_is_history_mark", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 191, Name = "trap_obj_lockon_target", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 192, Name = "trap_obj_is_motion_cancel", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 193, Name = "trap_camera_warp", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 194, Name = "trap_obj_set_stealth", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 195, Name = "trap_obj_reset_stealth", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 196, Name = "trap_area_entrance", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 197, Name = "trap_area_cost_rest", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 198, Name = "trap_obj_set_player_random_pos", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 199, Name = "trap_obj_set_random_pos", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 200, Name = "trap_obj_set_bg_collision_type", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 201, Name = "trap_obj_dir", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 202, Name = "trap_unit_disable", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 203, Name = "trap_unit_enable", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 204, Name = "trap_status_force_leave_start", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 205, Name = "trap_status_force_leave_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 206, Name = "trap_status_is_force_leave", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 207, Name = "trap_camera_watch", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 208, Name = "trap_obj_is_hover", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 209, Name = "trap_obj_dead", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 210, Name = "trap_obj_search_by_part", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 211, Name = "trap_obj_pattern_enable", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 212, Name = "trap_obj_pattern_disable", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 213, Name = "trap_obj_part", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 214, Name = "trap_obj_hook_stop", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 217, Name = "trap_obj_set_pos_trans", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 218, Name = "trap_obj_set_unit_arg", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 219, Name = "trap_obj_camera_start", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 220, Name = "trap_obj_move_to_space", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 221, Name = "trap_obj_can_decide_command", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 222, Name = "trap_obj_get_entry_id", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 223, Name = "trap_camera_cancel", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 224, Name = "trap_obj_is_action_air", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 225, Name = "trap_obj_is_star", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 226, Name = "trap_obj_scatter_prize_mu", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 227, Name = "trap_obj_jump_direct", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 228, Name = "trap_sheet_hp", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 229, Name = "trap_sheet_max_hp", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 230, Name = "trap_sheet_hp_rate", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 231, Name = "trap_sheet_set_min_hp", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 232, Name = "trap_sheet_min_hp", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 233, Name = "trap_sheet_set_hp", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 234, Name = "trap_party_get_weapon", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 235, Name = "trap_party_hand_to_bone", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 236, Name = "trap_obj_motion_unsync", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 237, Name = "trap_command_override_top", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 238, Name = "trap_obj_motion_capture_id", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 239, Name = "trap_obj_is_unit_active", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 240, Name = "trap_obj_scatter_prize_tt", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 241, Name = "trap_act_shout", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 242, Name = "trap_player_capture_form", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 243, Name = "trap_player_capture_form_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 244, Name = "trap_status_is_battle", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 245, Name = "trap_target_clear_before_player", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 246, Name = "trap_target_clear_after_player", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 247, Name = "trap_bg_get_random_pos", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 248, Name = "trap_bg_get_random_pos_air", Flags = 0x40000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 249, Name = "trap_status_set_prize_ratio", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 250, Name = "trap_status_set_lockon_ratio", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 251, Name = "trap_light_fadein", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 252, Name = "trap_camera_apply_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 253, Name = "trap_obj_can_capture_control", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 254, Name = "trap_obj_is_ride", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 255, Name = "trap_obj_disable_occ", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 256, Name = "trap_obj_enable_occ", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 257, Name = "trap_light_set_fog_near", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 258, Name = "trap_light_set_fog_far", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 259, Name = "trap_light_set_fog_min", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 260, Name = "trap_light_set_fog_max", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 261, Name = "trap_sheet_munny", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 262, Name = "trap_obj_voice", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 263, Name = "trap_player_set_exec_rc", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 264, Name = "trap_status_secure_mode_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 265, Name = "trap_obj_set_medal", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 266, Name = "trap_obj_get_medal", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 267, Name = "trap_obj_scatter_medal", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 268, Name = "trap_obj_action_lightcycle", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 269, Name = "trap_obj_get_lightcycle_movement", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 270, Name = "trap_obj_motion_disable_anmatr_effect", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 271, Name = "trap_obj_motion_enable_anmatr_effect", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 272, Name = "trap_obj_is_dead", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 273, Name = "trap_signal_hook", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 274, Name = "trap_event_get_rest_time", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 275, Name = "trap_obj_recov_holylight", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 276, Name = "trap_obj_use_mp", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 277, Name = "trap_obj_reraise", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 278, Name = "trap_obj_scatter_prize_tr", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 279, Name = "trap_prize_appear_tr", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 280, Name = "trap_sheet_add_munny", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 281, Name = "trap_camera_begin_scope", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 283, Name = "trap_camera_end_scope", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 284, Name = "trap_tutorial_pause", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 285, Name = "trap_obj_show_picture", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 286, Name = "trap_status_hide_shadow", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 287, Name = "trap_status_show_shadow", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 288, Name = "trap_status_begin_free_ability", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 289, Name = "trap_status_end_free_ability", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 290, Name = "trap_picture_change", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 291, Name = "trap_obj_levelup_unit", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 292, Name = "trap_obj_search_by_unit_arg", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 293, Name = "trap_event_control_off", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 294, Name = "trap_event_control_on", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 295, Name = "trap_camera_reset", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 296, Name = "trap_tutorial_open", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 297, Name = "trap_player_get_rc", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 298, Name = "trap_worldwork_get", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 299, Name = "trap_area_set_next_entrance", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 300, Name = "trap_prize_num", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 301, Name = "trap_tutorial_is_open", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 302, Name = "trap_obj_set_skateboard_mode", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 303, Name = "trap_area_cost_ratio", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 304, Name = "trap_obj_search_by_glance", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 305, Name = "trap_camera_eye", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 306, Name = "trap_camera_at", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 307, Name = "trap_obj_search_by_camera", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 308, Name = "trap_obj_capture_command", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 309, Name = "trap_sysobj_is_player", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 310, Name = "trap_obj_get_weight", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 311, Name = "trap_sheet_set_element_rate", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 312, Name = "trap_camera_set_scope_zoom", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 313, Name = "trap_camera_set_scope_closeup_distance", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 314, Name = "trap_camera_set_scope_target_pos", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 315, Name = "trap_picture_set_pos", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 316, Name = "trap_camera_get_projection_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 317, Name = "trap_status_no_gameover", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 318, Name = "trap_obj_play_se", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 319, Name = "trap_sysobj_is_sora", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 320, Name = "trap_unit_get_enemy_num", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 321, Name = "trap_player_lockon", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 322, Name = "trap_command_enable_item", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 323, Name = "trap_obj_count_entry", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 324, Name = "trap_obj_pattern_reset", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 325, Name = "trap_obj_reaction_callback", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 326, Name = "trap_bg_set_animation_speed", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 327, Name = "trap_prize_get_all_tr", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 328, Name = "trap_obj_dead_mark", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 329, Name = "trap_sheet_set_prize_range", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 330, Name = "trap_obj_set_cannon_camera_offset", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 331, Name = "trap_obj_each_all", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 332, Name = "trap_sysobj_is_btlnpc", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 333, Name = "trap_obj_set_cannon_param", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 1, TrapIndex = 334, Name = "trap_command_enable", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 335, Name = "trap_obj_disable_occ_bone", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 336, Name = "trap_obj_enable_occ_bone", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 337, Name = "trap_command_set_side_b", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 338, Name = "trap_prize_return_ca", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 339, Name = "trap_prize_vacuum_ca", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 340, Name = "trap_prize_vacuum_range_ca", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 341, Name = "trap_prize_num_ca", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 342, Name = "trap_prize_appear_num", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 1, TrapIndex = 343, Name = "trap_obj_is_equip_ability", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 344, Name = "trap_obj_clear_occ", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 345, Name = "trap_command_override_slot", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 1, TrapIndex = 346, Name = "trap_command_slot_set_status", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 347, Name = "trap_obj_can_see", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 348, Name = "trap_sheet_set_hitback_addition", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 349, Name = "trap_obj_effect_kill_all", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 350, Name = "trap_status_close_pete_curtain", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 351, Name = "trap_status_open_pete_curtain", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 352, Name = "trap_area_set_return_tr", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 353, Name = "trap_obj_start_mpdrive", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 354, Name = "trap_event_layer_off", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 355, Name = "trap_player_can_capture_form", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 356, Name = "trap_event_layer_on", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 1, TrapIndex = 357, Name = "trap_sheet_attack_level", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 358, Name = "trap_sheet_set_attack_level", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 359, Name = "trap_obj_hook_command_image", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 360, Name = "trap_obj_reset_command_image", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 361, Name = "trap_sheet_level", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 362, Name = "trap_treasure_get", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 363, Name = "trap_prize_appear_xaldin", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 364, Name = "trap_jigsaw_get", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 1, TrapIndex = 365, Name = "trap_command_disable_group", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 366, Name = "trap_command_enable_group", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 1, TrapIndex = 367, Name = "trap_obj_get_move_to_space_pos", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 0, Name = "trap_enemy_exec_damage", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 1, Name = "trap_enemy_exec_damage_blow", Flags = 0x00000006 }, - new BdxTrap { TableIndex = 2, TrapIndex = 2, Name = "trap_enemy_exec_damage_small", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 3, Name = "trap_enemy_exec_damage_hitback", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 4, Name = "trap_enemy_each", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 5, Name = "trap_enemy_is_no_control", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 6, Name = "trap_enemy_is_damage_motion", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 7, Name = "trap_damage_reaction", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 8, Name = "trap_damage_is_reaction", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 9, Name = "trap_btlobj_set_sheet", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 10, Name = "trap_attack_new", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 11, Name = "trap_attack_set_radius", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 12, Name = "trap_attack_set_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 13, Name = "trap_attack_free", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 14, Name = "trap_attack_is_hit", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 15, Name = "trap_damage_exec_reaction", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 16, Name = "trap_damage_is_exec_reaction", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 17, Name = "trap_attack_strike", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 18, Name = "trap_attack_is_strike", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 19, Name = "trap_attack_set_line", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 20, Name = "trap_magic_start_thread", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 21, Name = "trap_teamwork_alloc", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 22, Name = "trap_attack_set_obj_pax", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 23, Name = "trap_btlobj_target", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 24, Name = "trap_attack_get_owner", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 25, Name = "trap_attack_get_param_id", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 26, Name = "trap_attack_exec_reflect", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 27, Name = "trap_enemy_exec_reflect", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 2, TrapIndex = 28, Name = "trap_attack_refresh", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 29, Name = "trap_attack_is_hit_bg", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 30, Name = "trap_attack_set_pax", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 31, Name = "trap_attack_dup", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 32, Name = "trap_damage_blow_up", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 33, Name = "trap_damage_blow_speed", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 34, Name = "trap_attack_get_type", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 35, Name = "trap_damage_attack_type", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 36, Name = "trap_enemy_add_damage", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 37, Name = "trap_attack_set_team", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 38, Name = "trap_attack_set_hit_callback", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 39, Name = "trap_attack_is_reflect", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 40, Name = "trap_attack_is_hit_wall", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 41, Name = "trap_attack_is_hit_floor", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 42, Name = "trap_attack_hit_bg_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 43, Name = "trap_attack_get_reflect_vector", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 44, Name = "trap_attack_reflecter", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 45, Name = "trap_damage_attack_param_id", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 46, Name = "trap_damage_damage", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 47, Name = "trap_limit_motion_start", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 48, Name = "trap_limit_player", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 49, Name = "trap_limit_friend", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 50, Name = "trap_limit_camera_start", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 51, Name = "trap_attack_set_rc", Flags = 0x00000005 }, - new BdxTrap { TableIndex = 2, TrapIndex = 52, Name = "trap_attack_rc_receiver", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 53, Name = "trap_enemy_last_dead", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 2, TrapIndex = 54, Name = "trap_limit_start_thread", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 55, Name = "trap_limit_light", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 56, Name = "trap_btlobj_lockon_target", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 57, Name = "trap_limit_effect_start", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 58, Name = "trap_limit_effect_start_pos", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 59, Name = "trap_limit_effect_start_bind", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 60, Name = "trap_limit_time", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 61, Name = "trap_attack_set_effect", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 62, Name = "trap_attack_set_time", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 63, Name = "trap_limit_reference", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 64, Name = "trap_damage_orig_reaction", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 65, Name = "trap_enemy_count_damager", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 2, TrapIndex = 66, Name = "trap_attack_get_reflect_count", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 67, Name = "trap_attack_new_combo_group", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 2, TrapIndex = 68, Name = "trap_magic_set_cost", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 69, Name = "trap_magic_can_add_cost", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 70, Name = "trap_damage_parts", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 71, Name = "trap_attack_set_hitmark_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 72, Name = "trap_damage_is_cure", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 73, Name = "trap_bonuslevel_up", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 74, Name = "trap_attack_set_reflect_callback", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 75, Name = "trap_summon_is_tink_exist", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 2, TrapIndex = 76, Name = "trap_enemy_set_karma_limit", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 77, Name = "trap_vacuum_create", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 78, Name = "trap_vacuum_destroy", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 79, Name = "trap_vacuum_set_ignore_type", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 80, Name = "trap_vacuum_set_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 81, Name = "trap_vacuum_set_speed", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 2, TrapIndex = 82, Name = "trap_vacuum_set_rot_speed", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 83, Name = "trap_vacuum_set_near_range", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 84, Name = "trap_vacuum_set_dist_rate", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 85, Name = "trap_damage_element", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 86, Name = "trap_damage_get_hitback", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 87, Name = "trap_enemy_exec_damage_large", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 2, TrapIndex = 88, Name = "trap_enemy_get_attacker", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 89, Name = "trap_limit_reset_special_command", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 90, Name = "trap_limit_close_gauge", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 91, Name = "trap_damage_get_reaction_type", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 92, Name = "trap_damage_is_finish", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 93, Name = "trap_damage_is_normal", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 94, Name = "trap_attack_set_system_pax", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 95, Name = "trap_btlobj_dup_sheet", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 2, TrapIndex = 96, Name = "trap_attack_is_valid", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 2, TrapIndex = 97, Name = "trap_enemy_set_attacker", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 2, Name = "trap_event_is_exec", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 3, Name = "trap_mission_complete", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 4, Name = "trap_mission_information", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 5, Name = "trap_mission_set_count", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 6, Name = "trap_mission_increment_count", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 7, Name = "trap_mission_restart_timer", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 8, Name = "trap_mission_set_gauge", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 9, Name = "trap_mission_add_gauge", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 10, Name = "trap_mission_set_gauge_ratio", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 11, Name = "trap_mission_failed", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 12, Name = "trap_mission_get_gauge_ratio", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 13, Name = "trap_mission_pause_timer", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 14, Name = "trap_mission_activate2d", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 15, Name = "trap_mission_deactivate2d", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 16, Name = "trap_mission_dead_boss", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 17, Name = "trap_mission_set_timer_param", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 4, TrapIndex = 18, Name = "trap_mission_set_count_param", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 4, TrapIndex = 19, Name = "trap_mission_set_gauge_param", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 4, TrapIndex = 20, Name = "trap_mission_decrement_count", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 21, Name = "trap_mission_is_activate2d", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 22, Name = "trap_mission_exit", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 23, Name = "trap_mission_reset_pause_mode", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 24, Name = "trap_mission_cancel_pause_timer", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 25, Name = "trap_mission_start_combo_counter", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 26, Name = "trap_mission_get_timer", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 27, Name = "trap_mission_stop_combo_counter", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 28, Name = "trap_mission_get_gauge_warning_ratio", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 29, Name = "trap_mission_get_count", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 30, Name = "trap_mission_get_max_combo_counter", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 31, Name = "trap_mission_get_combo_counter", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 32, Name = "trap_mission_return", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 33, Name = "trap_mission_add_combo_counter", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 34, Name = "trap_mission_is_gauge_warning", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 35, Name = "trap_score_type", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 36, Name = "trap_score_score", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 37, Name = "trap_score_update", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 4, TrapIndex = 38, Name = "trap_score_get", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 39, Name = "trap_mission_set_watch", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 40, Name = "trap_mission_get_timer_second", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 41, Name = "trap_mission_add_count", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 42, Name = "trap_struggle_increment", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 43, Name = "trap_mission_set_max_combo_counter", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 44, Name = "trap_mission_disable_count", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 45, Name = "trap_mission_disable_watch", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 46, Name = "trap_mission_set_warning_se", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 47, Name = "trap_mission_warning_timer", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 48, Name = "trap_mission_set_count_figure_num", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 4, TrapIndex = 49, Name = "trap_mission_disable_timer", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 50, Name = "trap_mission_warning_count", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 51, Name = "trap_mission_set_combo_counter_param", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 4, TrapIndex = 52, Name = "trap_mission_warning_combo_counter", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 4, TrapIndex = 53, Name = "trap_mission_set_combo_counter_warning_se", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 54, Name = "trap_mission_lock", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 55, Name = "trap_mission_is_lock", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 56, Name = "trap_event_continue_control_off", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 4, TrapIndex = 57, Name = "trap_mission_warning_gauge", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 4, TrapIndex = 58, Name = "trap_mission_reset_warning_count", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 0, Name = "trap_get_start_rtn_action", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 1, Name = "trap_set_path_way", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 2, Name = "trap_reverse_path_way", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 3, Name = "trap_get_path_dir", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 4, Name = "trap_end_rtn_action", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 5, Name = "trap_get_rtn_action", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 6, Name = "trap_get_rtn_action_dir", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 7, Name = "trap_is_rtn_change_dir", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 8, Name = "trap_create_active_path", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 9, Name = "trap_get_path_dir_from_obj", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 5, TrapIndex = 10, Name = "trap_forward_path_current_pointer", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 11, Name = "trap_is_end_rtn_action", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 12, Name = "trap_reset_active_path", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 13, Name = "trap_set_path_target_point", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 14, Name = "trap_get_path_point_pos", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 15, Name = "trap_clear_active_path", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 16, Name = "trap_reset_leave_way", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 17, Name = "trap_check_rtn_option_flag", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 18, Name = "trap_reset_path_current_pointer", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 19, Name = "trap_get_path_current_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 20, Name = "trap_get_path_current_dir", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 21, Name = "trap_get_path_first_point_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 22, Name = "trap_get_path_last_point_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 23, Name = "trap_set_path_by_id", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 24, Name = "trap_set_path_by_group", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 25, Name = "trap_get_path_dir_r", Flags = 0x40000003 }, - new BdxTrap { TableIndex = 5, TrapIndex = 26, Name = "trap_set_rtn_partner", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 27, Name = "trap_set_rtn_option_flag", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 28, Name = "trap_eh22_path_move_next", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 29, Name = "trap_eh22_path_move_before", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 30, Name = "trap_eh22_path_is_moving", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 31, Name = "trap_eh22_path_get_point", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 5, TrapIndex = 32, Name = "trap_eh22_path_play", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 5, TrapIndex = 33, Name = "trap_set_rtn_time_param", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 5, TrapIndex = 34, Name = "trap_get_obj_head_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 0, Name = "trap_camera_shake", Flags = 0x00000007 }, - new BdxTrap { TableIndex = 6, TrapIndex = 1, Name = "trap_prize_appear", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 2, Name = "trap_player_get_form", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 3, Name = "trap_target_searcher_init", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 4, Name = "trap_target_searcher_reset", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 5, Name = "trap_target_seracher_search", Flags = 0x00000007 }, - new BdxTrap { TableIndex = 6, TrapIndex = 6, Name = "trap_obj_stop", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 6, TrapIndex = 7, Name = "trap_obj_restart", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 8, Name = "trap_target_searcher_add", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 9, Name = "trap_target_dist", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 10, Name = "trap_obj_is_hit_attack", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 11, Name = "trap_target_searcher_search_obj", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 6, TrapIndex = 12, Name = "trap_target_searcher_get_old", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 6, TrapIndex = 13, Name = "trap_friend_force_warp", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 14, Name = "trap_friend_get", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 15, Name = "trap_friend_set_warp_level", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 16, Name = "trap_target_clear", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 17, Name = "trap_lockon_show", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 18, Name = "trap_lockon_hide", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 19, Name = "trap_status_peterpan_prize_drain_start", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 20, Name = "trap_status_peterpan_prize_drain_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 21, Name = "trap_target_searcher_add_target", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 22, Name = "trap_target_searcher_get_target_num", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 23, Name = "trap_obj_near_parts", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 24, Name = "trap_obj_get_bg_press", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 25, Name = "trap_obj_tt_ball_blow", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 26, Name = "trap_obj_limit_hover", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 27, Name = "trap_player_dice", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 28, Name = "trap_dice_set_spec", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 29, Name = "trap_player_card", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 30, Name = "trap_card_set_spec", Flags = 0x00000007 }, - new BdxTrap { TableIndex = 6, TrapIndex = 31, Name = "trap_limit_aladdin_prize_drain", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 6, TrapIndex = 32, Name = "trap_skateboard_ride", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 33, Name = "trap_skateboard_trick", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 6, TrapIndex = 34, Name = "trap_skateboard_trick_motion_push", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 6, TrapIndex = 35, Name = "trap_obj_attach_camera", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 36, Name = "trap_obj_detach_camera", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 37, Name = "trap_obj_is_attach_camera", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 38, Name = "trap_obj_limit_mulan_idle", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 39, Name = "trap_skateboard_ride_edge", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 40, Name = "trap_obj_limit_peterpan_idle", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 41, Name = "trap_skateboard_edge_jump", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 6, TrapIndex = 42, Name = "trap_obj_hop_direct", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 43, Name = "trap_command_limit_trinity_commbo_start", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 44, Name = "trap_obj_limit_riku_idle", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 45, Name = "trap_obj_hide_shadow", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 46, Name = "trap_obj_rc_stop_all", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 47, Name = "trap_obj_stop_end_all", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 48, Name = "trap_skateboardscore_add_count", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 49, Name = "trap_obj_is_stop", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 50, Name = "trap_obj_stop_start", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 51, Name = "trap_bghit_check_line", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 52, Name = "trap_bghit_get_normal", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 53, Name = "trap_bghit_is_hit", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 54, Name = "trap_bghit_get_cross_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 55, Name = "trap_bghit_get_kind", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 56, Name = "trap_target_set_group", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 57, Name = "trap_target_get_group", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 58, Name = "trap_obj_act_child_push", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 59, Name = "trap_xemnas_get_obj", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 60, Name = "trap_obj_set_stealth_color", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 6, TrapIndex = 61, Name = "trap_obj_is_hook", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 62, Name = "trap_obj_carpet_obj_idle", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 63, Name = "trap_obj_is_damage_motion", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 64, Name = "trap_obj_show_shadow", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 65, Name = "trap_obj_set_scissoring", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 66, Name = "trap_obj_clear_hitback", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 67, Name = "trap_obj_party_attack", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 68, Name = "trap_strike_raid_calc_xyzrot", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 69, Name = "trap_larxene_dead", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 6, TrapIndex = 70, Name = "trap_obj_play_se_loop", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 6, TrapIndex = 71, Name = "trap_obj_fadeout_se", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 0, Name = "trap_enemy_stop_all_start", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 1, Name = "trap_enemy_stop_all_end", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 2, Name = "trap_attack_hit_mark_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 3, Name = "trap_flare_init", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 4, Name = "trap_flare_new", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 5, Name = "trap_flare_free", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 6, Name = "trap_flare_set_pos", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 7, Name = "trap_flare_set_radius", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 7, TrapIndex = 8, Name = "trap_flare_set_effect", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 9, Name = "trap_flare_set_target", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 10, Name = "trap_flare_get_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 11, Name = "trap_flare_is_empty", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 12, Name = "trap_limit_aladdin_exclamation_mark_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 13, Name = "trap_magic_calc_speed", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 7, TrapIndex = 14, Name = "trap_attack_set_reaction_offset", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 15, Name = "trap_friend_get_target_size", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 16, Name = "trap_friend_get_current_action", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 17, Name = "trap_friend_set_script_status", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 18, Name = "trap_friend_get_main_status", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 19, Name = "trap_friend_update_target", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 21, Name = "trap_obj_limit_hover_set_spec", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 24, Name = "trap_friend_enable_system_wishdir", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 25, Name = "trap_friend_disable_system_wishdir", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 26, Name = "trap_friend_call", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 27, Name = "trap_limit_start_command", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 28, Name = "trap_trinity_shot_init", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 29, Name = "trap_trinity_shot_start", Flags = 0x40000004 }, - new BdxTrap { TableIndex = 7, TrapIndex = 30, Name = "trap_trinity_shot_ensure", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 31, Name = "trap_trinity_shot_set_effect_id", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 32, Name = "trap_vacuum_set_effective_range", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 33, Name = "trap_enemy_summon_entry", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 7, TrapIndex = 34, Name = "trap_attack_set_rc_owner", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 7, TrapIndex = 35, Name = "trap_summon_is_exec", Flags = 0x40000000 }, - new BdxTrap { TableIndex = 7, TrapIndex = 36, Name = "trap_limit_reset_hit_counter", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 8, TrapIndex = 0, Name = "trap_obj_target_radius", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 8, TrapIndex = 1, Name = "trap_player_push_ability_button", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 8, TrapIndex = 2, Name = "trap_obj_set_xyzrot", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 8, TrapIndex = 3, Name = "trap_special_last_xemnus_laser_start", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 8, TrapIndex = 4, Name = "trap_special_last_xemnus_laser_attack", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 8, TrapIndex = 5, Name = "trap_special_last_xemnus_laser_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 8, TrapIndex = 6, Name = "trap_special_last_xemnus_laser_optimize", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 8, TrapIndex = 7, Name = "trap_special_last_xemnus_laser_optimize_end", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 8, TrapIndex = 8, Name = "trap_camera_apply_inverse_pos", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 0, Name = "trap_empty_func", Flags = 0x00000000 }, - new BdxTrap { TableIndex = 10, TrapIndex = 1, Name = "trap_stitch_set_screen_position", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 2, Name = "trap_stitch_get_screen_position", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 3, Name = "trap_friend_start_limit", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 4, Name = "trap_friend_end_limit", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 5, Name = "trap_chickenlittle_get_shoot_target", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 6, Name = "trap_obj_set_special_command", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 7, Name = "trap_obj_reset_special_command", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 8, Name = "trap_friend_get_target_last_position", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 9, Name = "trap_genie_change_form", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 10, Name = "trap_genie_get_limit_command", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 11, Name = "trap_obj_set_stop_timer", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 10, TrapIndex = 12, Name = "trap_stitch_effect_start", Flags = 0x40000008 }, - new BdxTrap { TableIndex = 10, TrapIndex = 13, Name = "trap_stitch_shot_effect", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 14, Name = "trap_friend_set_target", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 10, TrapIndex = 15, Name = "trap_sysobj_motion_cont_push", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 10, TrapIndex = 16, Name = "trap_stitch_effect_kill", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 17, Name = "trap_sysobj_is_zako", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 18, Name = "trap_sysobj_is_boss", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 19, Name = "trap_sysobj_is_limit", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 20, Name = "trap_friend_follow_player", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 21, Name = "trap_friend_follow_enemy", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 22, Name = "trap_sysobj_is_blow", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 23, Name = "trap_enemy_is_attacked_from", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 24, Name = "tarp_friend_is_equiped_ability", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 25, Name = "trap_peterpan_receive_notify_player_target", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 26, Name = "trap_peterpan_accept_notify_player_target", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 27, Name = "trap_friend_enable_inertia", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 28, Name = "trap_friend_disable_inertia", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 29, Name = "trap_friend_use_item", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 10, TrapIndex = 30, Name = "trap_sysobj_is_finish_blow", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 31, Name = "trap_sysobj_is_summon", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 32, Name = "trap_stitch_move_request", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 33, Name = "trap_friend_get_player_attacker", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 34, Name = "trap_friend_remove_player_attacker", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 35, Name = "trap_friend_get_action_param", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 36, Name = "trap_friend_is_control", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 37, Name = "trap_friend_is_moveonly", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 38, Name = "trap_attack_is_finish", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 39, Name = "trap_friend_action_clear", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 40, Name = "trap_obj_is_motion_sync", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 41, Name = "trap_friend_start_leave", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 42, Name = "trap_friend_is_start_leave", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 43, Name = "trap_obj_set_use_mp", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 44, Name = "trap_obj_is_tornado", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 45, Name = "trap_sheet_get_drive_time", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 46, Name = "trap_friend_disable_follow_enemy", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 47, Name = "trap_friend_enable_follow_enemy", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 48, Name = "trap_friend_disable_follow_player", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 49, Name = "trap_friend_enable_follow_player", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 50, Name = "trap_sheet_get_mp", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 51, Name = "trap_chickenlittle_get_nearest_target", Flags = 0x00000004 }, - new BdxTrap { TableIndex = 10, TrapIndex = 52, Name = "trap_btlobj_is_reflect_motion", Flags = 0x40000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 53, Name = "trap_friend_add_watch_effect", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 54, Name = "trap_friend_is_effect_exist", Flags = 0x40000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 55, Name = "trap_target_searcher_set_check_hide_from_friend", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 56, Name = "trap_friend_invalidate_warp_point", Flags = 0x00000002 }, - new BdxTrap { TableIndex = 10, TrapIndex = 57, Name = "trap_friend_add_warp_point", Flags = 0x00000001 }, - new BdxTrap { TableIndex = 10, TrapIndex = 58, Name = "trap_friend_link_magic", Flags = 0x00000003 }, - new BdxTrap { TableIndex = 10, TrapIndex = 59, Name = "trap_chickenlittle_set_shoot_target", Flags = 0x00000002 }, - - #endregion - }; - } -} +using System.Collections.Generic; + +namespace OpenKh.Kh2.Bdx.Models +{ + public class BdxTraps + { + public static IEnumerable GetTraps() => _traps; + + private static readonly BdxTrap[] _traps = new[] + { + #region Generated + + new BdxTrap { TableIndex = 0, TrapIndex = 0, Name = "trap_puti", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 1, Name = "trap_putf", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 2, Name = "trap_puts", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 3, Name = "trap_frametime", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 4, Name = "trap_vector_add", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 5, Name = "trap_vector_sub", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 6, Name = "trap_vector_len", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 7, Name = "trap_vector_normalize", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 8, Name = "trap_vector_dump", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 9, Name = "trap_thread_start", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 0, TrapIndex = 11, Name = "trap_file_is_reading", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 12, Name = "trap_file_flush", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 13, Name = "trap_vector_roty", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 14, Name = "trap_progress_set_flag", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 15, Name = "trap_progress_check_flag", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 16, Name = "trap_random_get", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 17, Name = "trap_random_getf", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 18, Name = "trap_random_range", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 19, Name = "trap_worldflag_set", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 20, Name = "trap_worldflag_check", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 21, Name = "trap_vector_get_rot_xz", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 22, Name = "trap_abs", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 23, Name = "trap_absf", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 24, Name = "trap_stputi", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 25, Name = "trap_stputf", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 26, Name = "trap_stputs", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 27, Name = "func_system_set_game_speed", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 28, Name = "method_blur_init", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 29, Name = "method_blur_start", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 30, Name = "method_blur_stop", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 31, Name = "func_screen_whiteout", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 32, Name = "func_screen_whitein", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 35, Name = "method_vector_scale", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 36, Name = "trap_vector_mul", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 37, Name = "trap_vector_div", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 38, Name = "trap_effect_set_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 39, Name = "trap_effect_set_scale", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 40, Name = "trap_effect_set_rot", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 41, Name = "trap_effect_set_dir", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 42, Name = "trap_vector_atan_xz", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 43, Name = "trap_fixrad", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 44, Name = "trap_effect_loop_end", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 45, Name = "trap_vector_addf", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 46, Name = "trap_vector_homing", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 47, Name = "trap_memory_alloc", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 48, Name = "trap_memory_free", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 49, Name = "trap_effect_is_alive", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 50, Name = "trap_effect_is_active", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 51, Name = "trap_effect_kill", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 52, Name = "trap_effect_fadeout", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 53, Name = "trap_effect_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 54, Name = "trap_effect_dir", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 55, Name = "trap_timer_count_down", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 56, Name = "trap_timer_count_up", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 57, Name = "trap_saveflag_set", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 58, Name = "trap_saveflag_reset", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 59, Name = "trap_saveflag_check", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 60, Name = "trap_assert", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 61, Name = "trap_saveram_get_partram", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 62, Name = "trap_partram_set_item_max", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 63, Name = "trap_item_get", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 64, Name = "trap_sound_disable", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 65, Name = "trap_sound_play_system", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 66, Name = "trap_effect_pause", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 67, Name = "trap_effect_set_color", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 68, Name = "trap_vector_rotx", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 69, Name = "trap_menuflag_set", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 70, Name = "trap_progress_is_second", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 73, Name = "trap_menuflag_reset", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 74, Name = "trap_screen_show_picture", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 75, Name = "trap_saveram_set_weapon", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 76, Name = "trap_saveram_set_form_weapon", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 77, Name = "trap_screen_cross_fade", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 78, Name = "trap_vector_inter", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 79, Name = "trap_effect_add_dead_block", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 80, Name = "trap_pad_is_button", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 81, Name = "trap_pad_is_trigger", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 82, Name = "trap_vector_outer_product", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 83, Name = "trap_vector_rot", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 84, Name = "trap_vector_angle", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 85, Name = "trap_effect_loop_end_kill", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 86, Name = "trap_effect_set_type", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 87, Name = "trap_screen_fadeout", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 88, Name = "trap_screen_fadein", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 89, Name = "trap_menuflag_check", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 90, Name = "trap_vector_draw", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 0, TrapIndex = 91, Name = "trap_vector_inner_prodcut", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 92, Name = "trap_partram_add_attack", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 93, Name = "trap_partram_add_wisdom", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 94, Name = "trap_partram_add_defence", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 95, Name = "trap_partram_set_levelup_type", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 96, Name = "trap_partram_add_ap", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 97, Name = "trap_item_reduce", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 98, Name = "trap_saveram_set_form_ability", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 0, TrapIndex = 99, Name = "trap_partram_add_ability", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 0, TrapIndex = 100, Name = "trap_saveram_increment_friend_recov", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 101, Name = "trap_progress_is_secret_movie", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 102, Name = "trap_vector_to_angle", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 0, TrapIndex = 103, Name = "trap_progress_is_fm_secret_movie", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 0, TrapIndex = 104, Name = "trap_sound_set_bgse_volume", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 0, Name = "trap_sysobj_appear", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 1, Name = "trap_obj_set_rot", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 2, Name = "trap_sysobj_moveto", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 3, Name = "trap_sysobj_player", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 4, Name = "trap_obj_wish_dir", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 5, Name = "trap_act_table_init", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 6, Name = "trap_act_table_add", Flags = 0x0000000C }, + new BdxTrap { TableIndex = 1, TrapIndex = 7, Name = "trap_obj_set_act_table", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 8, Name = "trap_obj_act_start", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 9, Name = "trap_obj_act_push", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 10, Name = "trap_obj_is_act_exec", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 11, Name = "trap_sysobj_motion_start", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 12, Name = "trap_sysobj_motion_change", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 13, Name = "trap_sysobj_motion_push", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 14, Name = "trap_sysobj_motion_is_end", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 15, Name = "trap_sysobj_motion_id", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 17, Name = "trap_obj_leave_force", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 18, Name = "trap_obj_attach", Flags = 0x00000006 }, + new BdxTrap { TableIndex = 1, TrapIndex = 19, Name = "trap_sysobj_fadeout", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 20, Name = "trap_sysobj_fadein", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 21, Name = "trap_obj_effect_start", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 22, Name = "trap_obj_effect_start_pos", Flags = 0x40000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 23, Name = "trap_area_world", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 24, Name = "trap_area_area", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 25, Name = "trap_area_map_set", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 26, Name = "trap_area_battle_set", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 27, Name = "trap_area_event_set", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 28, Name = "trap_obj_leave", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 29, Name = "trap_obj_motion_capture", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 30, Name = "trap_area_jump", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 31, Name = "trap_area_setjump", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 32, Name = "trap_message_open", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 33, Name = "trap_message_close", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 34, Name = "trap_event_is_exec", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 35, Name = "trap_area_init", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 36, Name = "trap_bg_hide", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 37, Name = "trap_bg_show", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 38, Name = "trap_obj_set_team", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 39, Name = "trap_obj_unit_arg", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 40, Name = "trap_obj_is_pirate_shade", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 41, Name = "trap_signal_call", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 42, Name = "func_obj_control_off", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 43, Name = "func_obj_control_on", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 44, Name = "func_history_clear_enemy", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 45, Name = "func_area_activate_unit", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 46, Name = "func_bg_barrier_on", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 47, Name = "func_bg_barrier_off", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 48, Name = "method_message_is_end", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 49, Name = "method_obj_enable_reaction_command", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 50, Name = "method_obj_disable_reaction_command", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 51, Name = "method_obj_reset_reaction_command", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 52, Name = "method_obj_enable_collision", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 53, Name = "method_obj_disable_collision", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 54, Name = "method_obj_reset_collision", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 55, Name = "method_obj_jump", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 56, Name = "method_obj_is_culling", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 57, Name = "trap_obj_is_jump", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 58, Name = "trap_obj_fly", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 59, Name = "trap_obj_is_fly", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 60, Name = "trap_obj_is_air", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 61, Name = "trap_sysobj_motion_frame_start", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 62, Name = "trap_obj_get_moved", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 63, Name = "trap_obj_is_motion_in_loop", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 64, Name = "trap_obj_get_wish_movement", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 65, Name = "trap_obj_exec_fall", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 66, Name = "trap_obj_exec_land", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 67, Name = "trap_obj_motion_get_length", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 68, Name = "trap_obj_motion_get_loop_top", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 69, Name = "trap_obj_motion_get_time", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 70, Name = "trap_obj_set_flag", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 71, Name = "trap_obj_reset_flag", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 72, Name = "trap_obj_check_flag", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 73, Name = "trap_obj_hover", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 74, Name = "trap_obj_idle", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 75, Name = "trap_obj_motion_hook", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 76, Name = "trap_obj_motion_unhook", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 77, Name = "trap_obj_motion_is_hook", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 78, Name = "trap_obj_motion_is_no_control", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 79, Name = "trap_obj_set_dir", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 80, Name = "trap_obj_turn_dir", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 81, Name = "trap_obj_act_wedge", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 82, Name = "trap_obj_thread_start", Flags = 0x40000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 83, Name = "trap_obj_apply_bone_matrix", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 84, Name = "trap_obj_sheet", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 85, Name = "trap_obj_texanm_start", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 86, Name = "trap_obj_texanm_stop", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 87, Name = "trap_obj_effect_start_bind", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 88, Name = "trap_obj_target_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 89, Name = "trap_obj_move_request", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 90, Name = "trap_obj_act_shout", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 91, Name = "trap_obj_star", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 92, Name = "trap_obj_scatter_prize", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 93, Name = "trap_sysobj_party", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 94, Name = "trap_sysobj_is_exist", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 95, Name = "trap_obj_fly_to_jump", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 96, Name = "trap_obj_get_action", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 97, Name = "trap_obj_spec", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 98, Name = "trap_obj_step_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 99, Name = "trap_obj_float_height", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 100, Name = "trap_obj_jump_height_to_uptime", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 101, Name = "trap_obj_motion_is_capture", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 102, Name = "trap_obj_detach", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 103, Name = "trap_obj_set_detach_callback", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 104, Name = "trap_obj_shadow_move_start", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 105, Name = "trap_obj_shadow_move_end", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 106, Name = "trap_signal_reserve_hp", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 107, Name = "trap_obj_motion_speed", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 108, Name = "trap_obj_show_part", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 109, Name = "trap_obj_hide_part", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 110, Name = "trap_obj_get_appear_way", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 111, Name = "trap_obj_set_movement", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 112, Name = "trap_obj_hook", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 113, Name = "trap_player_get_movement", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 114, Name = "trap_obj_search_by_entry", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 115, Name = "trap_obj_set_jump_motion", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 117, Name = "trap_command_cage_on", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 118, Name = "trap_command_cage_off", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 119, Name = "trap_obj_check_step", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 120, Name = "trap_target_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 121, Name = "trap_target_search", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 122, Name = "trap_obj_dump", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 123, Name = "trap_obj_tex_fade_set", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 124, Name = "trap_obj_is_entry_fly", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 125, Name = "trap_obj_tex_fade_start", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 126, Name = "trap_obj_motion_sync", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 127, Name = "trap_obj_act_clear", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 128, Name = "trap_obj_sysjump", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 129, Name = "trap_obj_blow", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 130, Name = "trap_obj_cmp", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 131, Name = "trap_target_dup", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 132, Name = "trap_target_free", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 133, Name = "trap_obj_hide", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 134, Name = "trap_obj_show", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 135, Name = "trap_bg_cross_pos", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 136, Name = "trap_bg_is_floor", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 137, Name = "trap_bg_get_normal", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 138, Name = "trap_pax_start", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 139, Name = "trap_pax_start_bind", Flags = 0x40000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 140, Name = "trap_target_is_exist", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 141, Name = "trap_bg_ground_pos", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 142, Name = "trap_signal_reserve_min_hp", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 143, Name = "trap_obj_search_by_serial", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 144, Name = "trap_obj_serial", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 145, Name = "trap_obj_touch_zone", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 146, Name = "trap_obj_hitback", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 147, Name = "trap_obj_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 148, Name = "trap_obj_set_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 149, Name = "trap_obj_effect_start_bind_other", Flags = 0x40000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 150, Name = "trap_obj_motion_check_range", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 151, Name = "trap_obj_motion_check_trigger", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 152, Name = "trap_status_is_mission", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 153, Name = "trap_obj_reset_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 154, Name = "trap_status_secure_mode_start", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 155, Name = "trap_obj_add_hp", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 156, Name = "trap_obj_hop", Flags = 0x00000007 }, + new BdxTrap { TableIndex = 1, TrapIndex = 157, Name = "trap_obj_camera_start", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 158, Name = "trap_bg_set_belt_conveyor", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 159, Name = "trap_bg_set_uvscroll_speed", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 160, Name = "trap_target_set_obj", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 161, Name = "trap_obj_is_attach", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 162, Name = "trap_target_set_before_player", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 163, Name = "trap_target_set_after_player", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 164, Name = "trap_obj_camera_start_global", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 165, Name = "trap_command_override", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 166, Name = "trap_target_attack", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 167, Name = "trap_obj_act_start_pri", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 168, Name = "trap_obj_flyjump", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 169, Name = "trap_obj_effect_unbind", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 170, Name = "trap_obj_unit_group", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 171, Name = "trap_status_no_leave", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 172, Name = "trap_obj_can_look", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 173, Name = "trap_obj_can_look_pos", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 174, Name = "trap_obj_look_start", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 175, Name = "trap_obj_look_start_pos", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 176, Name = "trap_obj_look_end", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 177, Name = "trap_obj_set_path", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 178, Name = "trap_obj_get_path_movement", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 179, Name = "trap_obj_set_fall_motion", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 180, Name = "trap_obj_set_land_motion", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 181, Name = "trap_light_create", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 182, Name = "trap_light_set_flag", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 183, Name = "trap_light_set_color", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 184, Name = "trap_light_fadeout", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 185, Name = "trap_obj_set_parts_color", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 186, Name = "trap_obj_reset_parts_color", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 187, Name = "trap_status_prize_drain_start", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 188, Name = "trap_status_prize_drain_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 189, Name = "trap_obj_history_mark", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 190, Name = "trap_obj_is_history_mark", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 191, Name = "trap_obj_lockon_target", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 192, Name = "trap_obj_is_motion_cancel", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 193, Name = "trap_camera_warp", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 194, Name = "trap_obj_set_stealth", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 195, Name = "trap_obj_reset_stealth", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 196, Name = "trap_area_entrance", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 197, Name = "trap_area_cost_rest", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 198, Name = "trap_obj_set_player_random_pos", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 199, Name = "trap_obj_set_random_pos", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 200, Name = "trap_obj_set_bg_collision_type", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 201, Name = "trap_obj_dir", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 202, Name = "trap_unit_disable", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 203, Name = "trap_unit_enable", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 204, Name = "trap_status_force_leave_start", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 205, Name = "trap_status_force_leave_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 206, Name = "trap_status_is_force_leave", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 207, Name = "trap_camera_watch", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 208, Name = "trap_obj_is_hover", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 209, Name = "trap_obj_dead", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 210, Name = "trap_obj_search_by_part", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 211, Name = "trap_obj_pattern_enable", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 212, Name = "trap_obj_pattern_disable", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 213, Name = "trap_obj_part", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 214, Name = "trap_obj_hook_stop", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 217, Name = "trap_obj_set_pos_trans", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 218, Name = "trap_obj_set_unit_arg", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 219, Name = "trap_obj_camera_start", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 220, Name = "trap_obj_move_to_space", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 221, Name = "trap_obj_can_decide_command", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 222, Name = "trap_obj_get_entry_id", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 223, Name = "trap_camera_cancel", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 224, Name = "trap_obj_is_action_air", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 225, Name = "trap_obj_is_star", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 226, Name = "trap_obj_scatter_prize_mu", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 227, Name = "trap_obj_jump_direct", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 228, Name = "trap_sheet_hp", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 229, Name = "trap_sheet_max_hp", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 230, Name = "trap_sheet_hp_rate", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 231, Name = "trap_sheet_set_min_hp", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 232, Name = "trap_sheet_min_hp", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 233, Name = "trap_sheet_set_hp", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 234, Name = "trap_party_get_weapon", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 235, Name = "trap_party_hand_to_bone", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 236, Name = "trap_obj_motion_unsync", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 237, Name = "trap_command_override_top", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 238, Name = "trap_obj_motion_capture_id", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 239, Name = "trap_obj_is_unit_active", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 240, Name = "trap_obj_scatter_prize_tt", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 241, Name = "trap_act_shout", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 242, Name = "trap_player_capture_form", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 243, Name = "trap_player_capture_form_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 244, Name = "trap_status_is_battle", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 245, Name = "trap_target_clear_before_player", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 246, Name = "trap_target_clear_after_player", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 247, Name = "trap_bg_get_random_pos", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 248, Name = "trap_bg_get_random_pos_air", Flags = 0x40000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 249, Name = "trap_status_set_prize_ratio", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 250, Name = "trap_status_set_lockon_ratio", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 251, Name = "trap_light_fadein", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 252, Name = "trap_camera_apply_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 253, Name = "trap_obj_can_capture_control", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 254, Name = "trap_obj_is_ride", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 255, Name = "trap_obj_disable_occ", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 256, Name = "trap_obj_enable_occ", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 257, Name = "trap_light_set_fog_near", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 258, Name = "trap_light_set_fog_far", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 259, Name = "trap_light_set_fog_min", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 260, Name = "trap_light_set_fog_max", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 261, Name = "trap_sheet_munny", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 262, Name = "trap_obj_voice", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 263, Name = "trap_player_set_exec_rc", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 264, Name = "trap_status_secure_mode_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 265, Name = "trap_obj_set_medal", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 266, Name = "trap_obj_get_medal", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 267, Name = "trap_obj_scatter_medal", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 268, Name = "trap_obj_action_lightcycle", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 269, Name = "trap_obj_get_lightcycle_movement", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 270, Name = "trap_obj_motion_disable_anmatr_effect", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 271, Name = "trap_obj_motion_enable_anmatr_effect", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 272, Name = "trap_obj_is_dead", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 273, Name = "trap_signal_hook", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 274, Name = "trap_event_get_rest_time", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 275, Name = "trap_obj_recov_holylight", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 276, Name = "trap_obj_use_mp", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 277, Name = "trap_obj_reraise", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 278, Name = "trap_obj_scatter_prize_tr", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 279, Name = "trap_prize_appear_tr", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 280, Name = "trap_sheet_add_munny", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 281, Name = "trap_camera_begin_scope", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 283, Name = "trap_camera_end_scope", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 284, Name = "trap_tutorial_pause", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 285, Name = "trap_obj_show_picture", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 286, Name = "trap_status_hide_shadow", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 287, Name = "trap_status_show_shadow", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 288, Name = "trap_status_begin_free_ability", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 289, Name = "trap_status_end_free_ability", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 290, Name = "trap_picture_change", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 291, Name = "trap_obj_levelup_unit", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 292, Name = "trap_obj_search_by_unit_arg", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 293, Name = "trap_event_control_off", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 294, Name = "trap_event_control_on", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 295, Name = "trap_camera_reset", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 296, Name = "trap_tutorial_open", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 297, Name = "trap_player_get_rc", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 298, Name = "trap_worldwork_get", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 299, Name = "trap_area_set_next_entrance", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 300, Name = "trap_prize_num", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 301, Name = "trap_tutorial_is_open", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 302, Name = "trap_obj_set_skateboard_mode", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 303, Name = "trap_area_cost_ratio", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 304, Name = "trap_obj_search_by_glance", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 305, Name = "trap_camera_eye", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 306, Name = "trap_camera_at", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 307, Name = "trap_obj_search_by_camera", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 308, Name = "trap_obj_capture_command", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 309, Name = "trap_sysobj_is_player", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 310, Name = "trap_obj_get_weight", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 311, Name = "trap_sheet_set_element_rate", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 312, Name = "trap_camera_set_scope_zoom", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 313, Name = "trap_camera_set_scope_closeup_distance", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 314, Name = "trap_camera_set_scope_target_pos", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 315, Name = "trap_picture_set_pos", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 316, Name = "trap_camera_get_projection_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 317, Name = "trap_status_no_gameover", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 318, Name = "trap_obj_play_se", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 319, Name = "trap_sysobj_is_sora", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 320, Name = "trap_unit_get_enemy_num", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 321, Name = "trap_player_lockon", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 322, Name = "trap_command_enable_item", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 323, Name = "trap_obj_count_entry", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 324, Name = "trap_obj_pattern_reset", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 325, Name = "trap_obj_reaction_callback", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 326, Name = "trap_bg_set_animation_speed", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 327, Name = "trap_prize_get_all_tr", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 328, Name = "trap_obj_dead_mark", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 329, Name = "trap_sheet_set_prize_range", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 330, Name = "trap_obj_set_cannon_camera_offset", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 331, Name = "trap_obj_each_all", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 332, Name = "trap_sysobj_is_btlnpc", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 333, Name = "trap_obj_set_cannon_param", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 1, TrapIndex = 334, Name = "trap_command_enable", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 335, Name = "trap_obj_disable_occ_bone", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 336, Name = "trap_obj_enable_occ_bone", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 337, Name = "trap_command_set_side_b", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 338, Name = "trap_prize_return_ca", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 339, Name = "trap_prize_vacuum_ca", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 340, Name = "trap_prize_vacuum_range_ca", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 341, Name = "trap_prize_num_ca", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 342, Name = "trap_prize_appear_num", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 1, TrapIndex = 343, Name = "trap_obj_is_equip_ability", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 344, Name = "trap_obj_clear_occ", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 345, Name = "trap_command_override_slot", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 1, TrapIndex = 346, Name = "trap_command_slot_set_status", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 347, Name = "trap_obj_can_see", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 348, Name = "trap_sheet_set_hitback_addition", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 349, Name = "trap_obj_effect_kill_all", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 350, Name = "trap_status_close_pete_curtain", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 351, Name = "trap_status_open_pete_curtain", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 352, Name = "trap_area_set_return_tr", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 353, Name = "trap_obj_start_mpdrive", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 354, Name = "trap_event_layer_off", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 355, Name = "trap_player_can_capture_form", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 356, Name = "trap_event_layer_on", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 1, TrapIndex = 357, Name = "trap_sheet_attack_level", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 358, Name = "trap_sheet_set_attack_level", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 359, Name = "trap_obj_hook_command_image", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 360, Name = "trap_obj_reset_command_image", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 361, Name = "trap_sheet_level", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 362, Name = "trap_treasure_get", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 363, Name = "trap_prize_appear_xaldin", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 364, Name = "trap_jigsaw_get", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 1, TrapIndex = 365, Name = "trap_command_disable_group", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 366, Name = "trap_command_enable_group", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 1, TrapIndex = 367, Name = "trap_obj_get_move_to_space_pos", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 0, Name = "trap_enemy_exec_damage", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 1, Name = "trap_enemy_exec_damage_blow", Flags = 0x00000006 }, + new BdxTrap { TableIndex = 2, TrapIndex = 2, Name = "trap_enemy_exec_damage_small", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 3, Name = "trap_enemy_exec_damage_hitback", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 4, Name = "trap_enemy_each", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 5, Name = "trap_enemy_is_no_control", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 6, Name = "trap_enemy_is_damage_motion", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 7, Name = "trap_damage_reaction", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 8, Name = "trap_damage_is_reaction", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 9, Name = "trap_btlobj_set_sheet", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 10, Name = "trap_attack_new", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 11, Name = "trap_attack_set_radius", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 12, Name = "trap_attack_set_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 13, Name = "trap_attack_free", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 14, Name = "trap_attack_is_hit", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 15, Name = "trap_damage_exec_reaction", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 16, Name = "trap_damage_is_exec_reaction", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 17, Name = "trap_attack_strike", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 18, Name = "trap_attack_is_strike", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 19, Name = "trap_attack_set_line", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 20, Name = "trap_magic_start_thread", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 21, Name = "trap_teamwork_alloc", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 22, Name = "trap_attack_set_obj_pax", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 23, Name = "trap_btlobj_target", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 24, Name = "trap_attack_get_owner", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 25, Name = "trap_attack_get_param_id", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 26, Name = "trap_attack_exec_reflect", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 27, Name = "trap_enemy_exec_reflect", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 2, TrapIndex = 28, Name = "trap_attack_refresh", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 29, Name = "trap_attack_is_hit_bg", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 30, Name = "trap_attack_set_pax", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 31, Name = "trap_attack_dup", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 32, Name = "trap_damage_blow_up", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 33, Name = "trap_damage_blow_speed", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 34, Name = "trap_attack_get_type", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 35, Name = "trap_damage_attack_type", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 36, Name = "trap_enemy_add_damage", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 37, Name = "trap_attack_set_team", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 38, Name = "trap_attack_set_hit_callback", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 39, Name = "trap_attack_is_reflect", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 40, Name = "trap_attack_is_hit_wall", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 41, Name = "trap_attack_is_hit_floor", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 42, Name = "trap_attack_hit_bg_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 43, Name = "trap_attack_get_reflect_vector", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 44, Name = "trap_attack_reflecter", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 45, Name = "trap_damage_attack_param_id", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 46, Name = "trap_damage_damage", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 47, Name = "trap_limit_motion_start", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 48, Name = "trap_limit_player", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 49, Name = "trap_limit_friend", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 50, Name = "trap_limit_camera_start", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 51, Name = "trap_attack_set_rc", Flags = 0x00000005 }, + new BdxTrap { TableIndex = 2, TrapIndex = 52, Name = "trap_attack_rc_receiver", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 53, Name = "trap_enemy_last_dead", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 2, TrapIndex = 54, Name = "trap_limit_start_thread", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 55, Name = "trap_limit_light", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 56, Name = "trap_btlobj_lockon_target", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 57, Name = "trap_limit_effect_start", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 58, Name = "trap_limit_effect_start_pos", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 59, Name = "trap_limit_effect_start_bind", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 60, Name = "trap_limit_time", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 61, Name = "trap_attack_set_effect", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 62, Name = "trap_attack_set_time", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 63, Name = "trap_limit_reference", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 64, Name = "trap_damage_orig_reaction", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 65, Name = "trap_enemy_count_damager", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 2, TrapIndex = 66, Name = "trap_attack_get_reflect_count", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 67, Name = "trap_attack_new_combo_group", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 2, TrapIndex = 68, Name = "trap_magic_set_cost", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 69, Name = "trap_magic_can_add_cost", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 70, Name = "trap_damage_parts", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 71, Name = "trap_attack_set_hitmark_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 72, Name = "trap_damage_is_cure", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 73, Name = "trap_bonuslevel_up", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 74, Name = "trap_attack_set_reflect_callback", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 75, Name = "trap_summon_is_tink_exist", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 2, TrapIndex = 76, Name = "trap_enemy_set_karma_limit", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 77, Name = "trap_vacuum_create", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 78, Name = "trap_vacuum_destroy", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 79, Name = "trap_vacuum_set_ignore_type", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 80, Name = "trap_vacuum_set_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 81, Name = "trap_vacuum_set_speed", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 2, TrapIndex = 82, Name = "trap_vacuum_set_rot_speed", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 83, Name = "trap_vacuum_set_near_range", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 84, Name = "trap_vacuum_set_dist_rate", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 85, Name = "trap_damage_element", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 86, Name = "trap_damage_get_hitback", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 87, Name = "trap_enemy_exec_damage_large", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 2, TrapIndex = 88, Name = "trap_enemy_get_attacker", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 89, Name = "trap_limit_reset_special_command", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 90, Name = "trap_limit_close_gauge", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 91, Name = "trap_damage_get_reaction_type", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 92, Name = "trap_damage_is_finish", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 93, Name = "trap_damage_is_normal", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 94, Name = "trap_attack_set_system_pax", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 95, Name = "trap_btlobj_dup_sheet", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 2, TrapIndex = 96, Name = "trap_attack_is_valid", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 2, TrapIndex = 97, Name = "trap_enemy_set_attacker", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 2, Name = "trap_event_is_exec", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 3, Name = "trap_mission_complete", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 4, Name = "trap_mission_information", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 5, Name = "trap_mission_set_count", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 6, Name = "trap_mission_increment_count", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 7, Name = "trap_mission_restart_timer", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 8, Name = "trap_mission_set_gauge", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 9, Name = "trap_mission_add_gauge", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 10, Name = "trap_mission_set_gauge_ratio", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 11, Name = "trap_mission_failed", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 12, Name = "trap_mission_get_gauge_ratio", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 13, Name = "trap_mission_pause_timer", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 14, Name = "trap_mission_activate2d", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 15, Name = "trap_mission_deactivate2d", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 16, Name = "trap_mission_dead_boss", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 17, Name = "trap_mission_set_timer_param", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 4, TrapIndex = 18, Name = "trap_mission_set_count_param", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 4, TrapIndex = 19, Name = "trap_mission_set_gauge_param", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 4, TrapIndex = 20, Name = "trap_mission_decrement_count", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 21, Name = "trap_mission_is_activate2d", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 22, Name = "trap_mission_exit", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 23, Name = "trap_mission_reset_pause_mode", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 24, Name = "trap_mission_cancel_pause_timer", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 25, Name = "trap_mission_start_combo_counter", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 26, Name = "trap_mission_get_timer", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 27, Name = "trap_mission_stop_combo_counter", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 28, Name = "trap_mission_get_gauge_warning_ratio", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 29, Name = "trap_mission_get_count", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 30, Name = "trap_mission_get_max_combo_counter", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 31, Name = "trap_mission_get_combo_counter", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 32, Name = "trap_mission_return", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 33, Name = "trap_mission_add_combo_counter", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 34, Name = "trap_mission_is_gauge_warning", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 35, Name = "trap_score_type", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 36, Name = "trap_score_score", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 37, Name = "trap_score_update", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 4, TrapIndex = 38, Name = "trap_score_get", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 39, Name = "trap_mission_set_watch", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 40, Name = "trap_mission_get_timer_second", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 41, Name = "trap_mission_add_count", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 42, Name = "trap_struggle_increment", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 43, Name = "trap_mission_set_max_combo_counter", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 44, Name = "trap_mission_disable_count", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 45, Name = "trap_mission_disable_watch", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 46, Name = "trap_mission_set_warning_se", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 47, Name = "trap_mission_warning_timer", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 48, Name = "trap_mission_set_count_figure_num", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 4, TrapIndex = 49, Name = "trap_mission_disable_timer", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 50, Name = "trap_mission_warning_count", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 51, Name = "trap_mission_set_combo_counter_param", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 4, TrapIndex = 52, Name = "trap_mission_warning_combo_counter", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 4, TrapIndex = 53, Name = "trap_mission_set_combo_counter_warning_se", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 54, Name = "trap_mission_lock", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 55, Name = "trap_mission_is_lock", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 56, Name = "trap_event_continue_control_off", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 4, TrapIndex = 57, Name = "trap_mission_warning_gauge", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 4, TrapIndex = 58, Name = "trap_mission_reset_warning_count", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 0, Name = "trap_get_start_rtn_action", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 1, Name = "trap_set_path_way", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 2, Name = "trap_reverse_path_way", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 3, Name = "trap_get_path_dir", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 4, Name = "trap_end_rtn_action", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 5, Name = "trap_get_rtn_action", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 6, Name = "trap_get_rtn_action_dir", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 7, Name = "trap_is_rtn_change_dir", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 8, Name = "trap_create_active_path", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 9, Name = "trap_get_path_dir_from_obj", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 5, TrapIndex = 10, Name = "trap_forward_path_current_pointer", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 11, Name = "trap_is_end_rtn_action", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 12, Name = "trap_reset_active_path", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 13, Name = "trap_set_path_target_point", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 14, Name = "trap_get_path_point_pos", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 15, Name = "trap_clear_active_path", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 16, Name = "trap_reset_leave_way", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 17, Name = "trap_check_rtn_option_flag", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 18, Name = "trap_reset_path_current_pointer", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 19, Name = "trap_get_path_current_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 20, Name = "trap_get_path_current_dir", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 21, Name = "trap_get_path_first_point_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 22, Name = "trap_get_path_last_point_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 23, Name = "trap_set_path_by_id", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 24, Name = "trap_set_path_by_group", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 25, Name = "trap_get_path_dir_r", Flags = 0x40000003 }, + new BdxTrap { TableIndex = 5, TrapIndex = 26, Name = "trap_set_rtn_partner", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 27, Name = "trap_set_rtn_option_flag", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 28, Name = "trap_eh22_path_move_next", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 29, Name = "trap_eh22_path_move_before", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 30, Name = "trap_eh22_path_is_moving", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 31, Name = "trap_eh22_path_get_point", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 5, TrapIndex = 32, Name = "trap_eh22_path_play", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 5, TrapIndex = 33, Name = "trap_set_rtn_time_param", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 5, TrapIndex = 34, Name = "trap_get_obj_head_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 0, Name = "trap_camera_shake", Flags = 0x00000007 }, + new BdxTrap { TableIndex = 6, TrapIndex = 1, Name = "trap_prize_appear", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 2, Name = "trap_player_get_form", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 3, Name = "trap_target_searcher_init", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 4, Name = "trap_target_searcher_reset", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 5, Name = "trap_target_seracher_search", Flags = 0x00000007 }, + new BdxTrap { TableIndex = 6, TrapIndex = 6, Name = "trap_obj_stop", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 6, TrapIndex = 7, Name = "trap_obj_restart", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 8, Name = "trap_target_searcher_add", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 9, Name = "trap_target_dist", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 10, Name = "trap_obj_is_hit_attack", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 11, Name = "trap_target_searcher_search_obj", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 6, TrapIndex = 12, Name = "trap_target_searcher_get_old", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 6, TrapIndex = 13, Name = "trap_friend_force_warp", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 14, Name = "trap_friend_get", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 15, Name = "trap_friend_set_warp_level", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 16, Name = "trap_target_clear", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 17, Name = "trap_lockon_show", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 18, Name = "trap_lockon_hide", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 19, Name = "trap_status_peterpan_prize_drain_start", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 20, Name = "trap_status_peterpan_prize_drain_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 21, Name = "trap_target_searcher_add_target", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 22, Name = "trap_target_searcher_get_target_num", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 23, Name = "trap_obj_near_parts", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 24, Name = "trap_obj_get_bg_press", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 25, Name = "trap_obj_tt_ball_blow", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 26, Name = "trap_obj_limit_hover", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 27, Name = "trap_player_dice", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 28, Name = "trap_dice_set_spec", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 29, Name = "trap_player_card", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 30, Name = "trap_card_set_spec", Flags = 0x00000007 }, + new BdxTrap { TableIndex = 6, TrapIndex = 31, Name = "trap_limit_aladdin_prize_drain", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 6, TrapIndex = 32, Name = "trap_skateboard_ride", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 33, Name = "trap_skateboard_trick", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 6, TrapIndex = 34, Name = "trap_skateboard_trick_motion_push", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 6, TrapIndex = 35, Name = "trap_obj_attach_camera", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 36, Name = "trap_obj_detach_camera", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 37, Name = "trap_obj_is_attach_camera", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 38, Name = "trap_obj_limit_mulan_idle", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 39, Name = "trap_skateboard_ride_edge", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 40, Name = "trap_obj_limit_peterpan_idle", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 41, Name = "trap_skateboard_edge_jump", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 6, TrapIndex = 42, Name = "trap_obj_hop_direct", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 43, Name = "trap_command_limit_trinity_commbo_start", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 44, Name = "trap_obj_limit_riku_idle", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 45, Name = "trap_obj_hide_shadow", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 46, Name = "trap_obj_rc_stop_all", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 47, Name = "trap_obj_stop_end_all", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 48, Name = "trap_skateboardscore_add_count", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 49, Name = "trap_obj_is_stop", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 50, Name = "trap_obj_stop_start", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 51, Name = "trap_bghit_check_line", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 52, Name = "trap_bghit_get_normal", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 53, Name = "trap_bghit_is_hit", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 54, Name = "trap_bghit_get_cross_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 55, Name = "trap_bghit_get_kind", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 56, Name = "trap_target_set_group", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 57, Name = "trap_target_get_group", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 58, Name = "trap_obj_act_child_push", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 59, Name = "trap_xemnas_get_obj", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 60, Name = "trap_obj_set_stealth_color", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 6, TrapIndex = 61, Name = "trap_obj_is_hook", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 62, Name = "trap_obj_carpet_obj_idle", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 63, Name = "trap_obj_is_damage_motion", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 64, Name = "trap_obj_show_shadow", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 65, Name = "trap_obj_set_scissoring", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 66, Name = "trap_obj_clear_hitback", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 67, Name = "trap_obj_party_attack", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 68, Name = "trap_strike_raid_calc_xyzrot", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 69, Name = "trap_larxene_dead", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 6, TrapIndex = 70, Name = "trap_obj_play_se_loop", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 6, TrapIndex = 71, Name = "trap_obj_fadeout_se", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 0, Name = "trap_enemy_stop_all_start", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 1, Name = "trap_enemy_stop_all_end", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 2, Name = "trap_attack_hit_mark_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 3, Name = "trap_flare_init", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 4, Name = "trap_flare_new", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 5, Name = "trap_flare_free", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 6, Name = "trap_flare_set_pos", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 7, Name = "trap_flare_set_radius", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 7, TrapIndex = 8, Name = "trap_flare_set_effect", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 9, Name = "trap_flare_set_target", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 10, Name = "trap_flare_get_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 11, Name = "trap_flare_is_empty", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 12, Name = "trap_limit_aladdin_exclamation_mark_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 13, Name = "trap_magic_calc_speed", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 7, TrapIndex = 14, Name = "trap_attack_set_reaction_offset", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 15, Name = "trap_friend_get_target_size", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 16, Name = "trap_friend_get_current_action", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 17, Name = "trap_friend_set_script_status", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 18, Name = "trap_friend_get_main_status", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 19, Name = "trap_friend_update_target", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 21, Name = "trap_obj_limit_hover_set_spec", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 24, Name = "trap_friend_enable_system_wishdir", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 25, Name = "trap_friend_disable_system_wishdir", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 26, Name = "trap_friend_call", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 27, Name = "trap_limit_start_command", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 28, Name = "trap_trinity_shot_init", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 29, Name = "trap_trinity_shot_start", Flags = 0x40000004 }, + new BdxTrap { TableIndex = 7, TrapIndex = 30, Name = "trap_trinity_shot_ensure", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 31, Name = "trap_trinity_shot_set_effect_id", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 32, Name = "trap_vacuum_set_effective_range", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 33, Name = "trap_enemy_summon_entry", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 7, TrapIndex = 34, Name = "trap_attack_set_rc_owner", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 7, TrapIndex = 35, Name = "trap_summon_is_exec", Flags = 0x40000000 }, + new BdxTrap { TableIndex = 7, TrapIndex = 36, Name = "trap_limit_reset_hit_counter", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 8, TrapIndex = 0, Name = "trap_obj_target_radius", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 8, TrapIndex = 1, Name = "trap_player_push_ability_button", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 8, TrapIndex = 2, Name = "trap_obj_set_xyzrot", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 8, TrapIndex = 3, Name = "trap_special_last_xemnus_laser_start", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 8, TrapIndex = 4, Name = "trap_special_last_xemnus_laser_attack", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 8, TrapIndex = 5, Name = "trap_special_last_xemnus_laser_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 8, TrapIndex = 6, Name = "trap_special_last_xemnus_laser_optimize", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 8, TrapIndex = 7, Name = "trap_special_last_xemnus_laser_optimize_end", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 8, TrapIndex = 8, Name = "trap_camera_apply_inverse_pos", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 0, Name = "trap_empty_func", Flags = 0x00000000 }, + new BdxTrap { TableIndex = 10, TrapIndex = 1, Name = "trap_stitch_set_screen_position", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 2, Name = "trap_stitch_get_screen_position", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 3, Name = "trap_friend_start_limit", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 4, Name = "trap_friend_end_limit", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 5, Name = "trap_chickenlittle_get_shoot_target", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 6, Name = "trap_obj_set_special_command", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 7, Name = "trap_obj_reset_special_command", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 8, Name = "trap_friend_get_target_last_position", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 9, Name = "trap_genie_change_form", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 10, Name = "trap_genie_get_limit_command", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 11, Name = "trap_obj_set_stop_timer", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 10, TrapIndex = 12, Name = "trap_stitch_effect_start", Flags = 0x40000008 }, + new BdxTrap { TableIndex = 10, TrapIndex = 13, Name = "trap_stitch_shot_effect", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 14, Name = "trap_friend_set_target", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 10, TrapIndex = 15, Name = "trap_sysobj_motion_cont_push", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 10, TrapIndex = 16, Name = "trap_stitch_effect_kill", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 17, Name = "trap_sysobj_is_zako", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 18, Name = "trap_sysobj_is_boss", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 19, Name = "trap_sysobj_is_limit", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 20, Name = "trap_friend_follow_player", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 21, Name = "trap_friend_follow_enemy", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 22, Name = "trap_sysobj_is_blow", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 23, Name = "trap_enemy_is_attacked_from", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 24, Name = "tarp_friend_is_equiped_ability", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 25, Name = "trap_peterpan_receive_notify_player_target", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 26, Name = "trap_peterpan_accept_notify_player_target", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 27, Name = "trap_friend_enable_inertia", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 28, Name = "trap_friend_disable_inertia", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 29, Name = "trap_friend_use_item", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 10, TrapIndex = 30, Name = "trap_sysobj_is_finish_blow", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 31, Name = "trap_sysobj_is_summon", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 32, Name = "trap_stitch_move_request", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 33, Name = "trap_friend_get_player_attacker", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 34, Name = "trap_friend_remove_player_attacker", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 35, Name = "trap_friend_get_action_param", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 36, Name = "trap_friend_is_control", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 37, Name = "trap_friend_is_moveonly", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 38, Name = "trap_attack_is_finish", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 39, Name = "trap_friend_action_clear", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 40, Name = "trap_obj_is_motion_sync", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 41, Name = "trap_friend_start_leave", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 42, Name = "trap_friend_is_start_leave", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 43, Name = "trap_obj_set_use_mp", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 44, Name = "trap_obj_is_tornado", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 45, Name = "trap_sheet_get_drive_time", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 46, Name = "trap_friend_disable_follow_enemy", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 47, Name = "trap_friend_enable_follow_enemy", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 48, Name = "trap_friend_disable_follow_player", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 49, Name = "trap_friend_enable_follow_player", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 50, Name = "trap_sheet_get_mp", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 51, Name = "trap_chickenlittle_get_nearest_target", Flags = 0x00000004 }, + new BdxTrap { TableIndex = 10, TrapIndex = 52, Name = "trap_btlobj_is_reflect_motion", Flags = 0x40000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 53, Name = "trap_friend_add_watch_effect", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 54, Name = "trap_friend_is_effect_exist", Flags = 0x40000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 55, Name = "trap_target_searcher_set_check_hide_from_friend", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 56, Name = "trap_friend_invalidate_warp_point", Flags = 0x00000002 }, + new BdxTrap { TableIndex = 10, TrapIndex = 57, Name = "trap_friend_add_warp_point", Flags = 0x00000001 }, + new BdxTrap { TableIndex = 10, TrapIndex = 58, Name = "trap_friend_link_magic", Flags = 0x00000003 }, + new BdxTrap { TableIndex = 10, TrapIndex = 59, Name = "trap_chickenlittle_set_shoot_target", Flags = 0x00000002 }, + + #endregion + }; + } +} diff --git a/OpenKh.Command.Bdxio/Utils/BdxAsciiModel.cs b/OpenKh.Kh2/Bdx/Utils/BdxAsciiModel.cs similarity index 94% rename from OpenKh.Command.Bdxio/Utils/BdxAsciiModel.cs rename to OpenKh.Kh2/Bdx/Utils/BdxAsciiModel.cs index 6802fae90..9c156cd96 100644 --- a/OpenKh.Command.Bdxio/Utils/BdxAsciiModel.cs +++ b/OpenKh.Kh2/Bdx/Utils/BdxAsciiModel.cs @@ -1,42 +1,45 @@ -namespace OpenKh.Command.Bdxio.Utils -{ - public class BdxAsciiModel - { - public bool IsEmpty { get; set; } - - public string? Header { get; set; } - public string? Script { get; set; } - - public int FirstHeaderLineNumber { get; set; } - public int FirstScriptLineNumber { get; set; } - - public string GetLineNumberRetainedScriptBody() => new string('\n', FirstScriptLineNumber) + Script; - - public static BdxAsciiModel ParseText(string body) - { - var lines = body.Replace("\r\n", "\n").Split('\n'); - int separator1 = Array.IndexOf(lines, "---"); - if (separator1 < 0) - { - throw new InvalidDataException(); - } - int separator2 = Array.IndexOf(lines, "---", separator1 + 1); - if (separator2 < 0) - { - throw new InvalidDataException(); - } - - var header = string.Join("\n", lines, separator1 + 1, separator2 - separator1 - 1); - var script = string.Join("\n", lines.Skip(separator2 + 1)); - - return new BdxAsciiModel - { - FirstHeaderLineNumber = 1 + separator1, - FirstScriptLineNumber = 1 + separator2, - IsEmpty = header.Trim().Length == 0 && script.Trim().Length == 0, - Header = header, - Script = script, - }; - } - } -} +using System; +using System.IO; + +namespace OpenKh.Kh2.Bdx.Utils +{ + public class BdxAsciiModel + { + public bool IsEmpty { get; set; } + + public string? Header { get; set; } + public string? Script { get; set; } + + public int FirstHeaderLineNumber { get; set; } + public int FirstScriptLineNumber { get; set; } + + public string GetLineNumberRetainedScriptBody() => new string('\n', FirstScriptLineNumber) + Script; + + public static BdxAsciiModel ParseText(string body) + { + var lines = body.Replace("\r\n", "\n").Split('\n'); + int separator1 = Array.IndexOf(lines, "---"); + if (separator1 < 0) + { + throw new InvalidDataException(); + } + int separator2 = Array.IndexOf(lines, "---", separator1 + 1); + if (separator2 < 0) + { + throw new InvalidDataException(); + } + + var header = string.Join("\n", lines, separator1 + 1, separator2 - separator1 - 1); + var script = string.Join("\n", lines.Skip(separator2 + 1)); + + return new BdxAsciiModel + { + FirstHeaderLineNumber = 1 + separator1, + FirstScriptLineNumber = 1 + separator2, + IsEmpty = header.Trim().Length == 0 && script.Trim().Length == 0, + Header = header, + Script = script, + }; + } + } +} diff --git a/OpenKh.Command.Bdxio/Utils/BdxDecoder.cs b/OpenKh.Kh2/Bdx/Utils/BdxDecoder.cs similarity index 96% rename from OpenKh.Command.Bdxio/Utils/BdxDecoder.cs rename to OpenKh.Kh2/Bdx/Utils/BdxDecoder.cs index 7782ab888..af6a22c85 100644 --- a/OpenKh.Command.Bdxio/Utils/BdxDecoder.cs +++ b/OpenKh.Kh2/Bdx/Utils/BdxDecoder.cs @@ -1,804 +1,808 @@ -using OpenKh.Command.Bdxio.Models; -using OpenKh.Common; -using System.Globalization; -using System.Text; -using Xe.BinaryMapper; -using YamlDotNet.Serialization; -using static OpenKh.Command.Bdxio.Models.BdxHeader; - -namespace OpenKh.Command.Bdxio.Utils -{ - public class BdxDecoder - { - public BdxHeader Header { get; } - - public IDictionary AddressAnnotated { get; } - public IDictionary AddressLabels { get; } - public IDictionary AddressComments { get; } - public IDictionary AddressCodeComments { get; } - public IDictionary WorkLabels { get; } - public string TopComment { get; set; } - - public BdxDecoder(Stream read, int[]? codeLabels = null, bool codeRevealer = false, bool codeRevealerLabeling = false) - { - if (read.Length == 0) - { - Header = new BdxHeader { IsEmpty = true }; - AddressAnnotated = new Dictionary(); - AddressLabels = new Dictionary(); - AddressComments = new Dictionary(); - AddressCodeComments = new Dictionary(); - WorkLabels = new Dictionary(); - TopComment = ""; - return; - } - - Header = BinaryMapping.ReadObject(read); - - var triggers = new List(); - while (true) - { - var one = BinaryMapping.ReadObject(read); - if (one.Key == 0 && one.Addr == 0) - { - break; - } - triggers.Add(one); - } - - int firstAddr = (12 + 8 * (triggers.Count + 1)) / 2; - - var addrAnnotated = new SortedDictionary(); - var addrLabels = new SortedDictionary(); - var addrComments = new SortedDictionary(); - var addrCodeComments = new SortedDictionary(); - var workLabels = new SortedDictionary(); - var topComment = ""; - - void AddAddr(int entry, string label) - { - if (addrLabels.TryGetValue(entry, out string? existing) && existing != null) - { - addrLabels[entry] = string.Join(",", existing.Split(',').Append(label).Distinct()); - } - else - { - addrLabels[entry] = label; - } - } - - void Walk(int entry) - { - var topAddr = entry; - - while (true) - { - var needClearance = false; - - if (addrAnnotated.TryGetValue(entry, out var annotHere)) - { - if (annotHere is IndeterminateContent) - { - needClearance = true; - } - else - { - return; - } - } - - var newPos = 16 + 2 * entry; - if (read.Length <= newPos) - { - // bug? - break; - } - - read.Position = newPos; - var codeWord = read.ReadUInt16(); - - var desc = BdxInstructionDescs.FindByCode(codeWord); - if (desc == null) - { - break; - } - - var code = new CodeContent(desc); - - if (needClearance) - { - var overrideDetected = false; - int x = 1; - for (; x < desc.CodeSize; x++) - { - if (true - && addrAnnotated.TryGetValue(entry + x, out var codePartHit) - && codePartHit is not IndeterminateContent - ) - { - overrideDetected = true; - break; - } - - if (addrLabels.TryGetValue(entry + x, out var codePartLabels)) - { - overrideDetected = true; - break; - } - } - if (overrideDetected) - { - addrComments[entry] = $"Although L{entry + x} is in IndeterminateContent area (L{entry} to L{entry + desc.CodeSize - 1}), there is a collision with text data? Maybe codeRevealer problem. Possibly need more better bottom text pool detection."; - break; - } - } - - addrAnnotated[entry] = code; - - if (desc.NeverReturn || desc.IsGosubRet) - { - break; - } - - if (desc.Args != null) - { - var parsedArgs = new List(); - - foreach (var arg in desc.Args) - { - var parsedArg = new ParsedArg(); - - int argValue; - if (arg.Type == BdxInstructionDesc.ArgType.Imm16) - { - argValue = read.ReadInt16(); - } - else if (arg.Type == BdxInstructionDesc.ArgType.Imm32) - { - argValue = read.ReadInt32(); - } - else if (arg.Type == BdxInstructionDesc.ArgType.Float32) - { - argValue = read.ReadInt32(); - parsedArg.PreferFloat32 = true; - } - else - { - argValue = new BdxInstruction(codeWord).Ssub; - } - - - if (arg.IsRelative) - { - var nextEntry = (ushort)(entry + (desc.CodeSize) + argValue); - - parsedArg.Value = nextEntry; - parsedArg.AddrRef = nextEntry; - - if (desc.IsJump || desc.IsGosub) - { - var newLabel = $"L{nextEntry}"; - parsedArg.Label = newLabel; - AddAddr(nextEntry, newLabel); - Walk(nextEntry); - } - } - else if (arg.AiPos) - { - parsedArg.Value = (ushort)argValue; - - var newLabel = $"L{(ushort)argValue}"; - parsedArg.Label = newLabel; - AddAddr((ushort)argValue, newLabel); - } - else if (arg.WorkPos) - { - parsedArg.Value = (ushort)argValue; - - var newLabel = $"W{(ushort)argValue}"; - parsedArg.Label = newLabel; - workLabels[(ushort)argValue] = newLabel; - } - else - { - parsedArg.Value = argValue; - } - - parsedArgs.Add(parsedArg); - } - - if (desc.IsSyscall) - { - var tableIdx = new BdxInstruction(codeWord).Ssub; - var trapIdx = parsedArgs[1].Value; - var trap = BdxTraps.GetTraps() - .FirstOrDefault(it => it.TableIndex == tableIdx && it.TrapIndex == trapIdx); - addrCodeComments[entry] = (trap != null) - ? $"{trap.Name} ({trap.Flags & 65535} in, {(((trap.Flags & 0x40000000) != 0) ? 1 : 0)} out)" - : "?"; - } - - code.Args = parsedArgs.ToArray(); - } - - for (int x = 1; x < desc.CodeSize; x++) - { - addrAnnotated[entry + x] = CodeArg.Value; - } - - if (desc.IsJump && !desc.IsJumpConditional) - { - break; - } - - entry += desc.CodeSize; - } - } - - var knownItems = BdxTrigger.GetKnownItems() - .ToDictionary( - one => one.Key, - one => one.Label - ); - - string GetTriggerLabelFor(int key) - { - if (knownItems.TryGetValue(key, out string? label) && label != null) - { - return label; - } - else - { - return $"TR{key}"; - } - } - - foreach (var trigger in triggers) - { - AddAddr(trigger.Addr, GetTriggerLabelFor(trigger.Key)); - Walk(trigger.Addr); - } - - foreach (var codeLabel in codeLabels ?? new int[0]) - { - AddAddr(codeLabel, $"L{codeLabel}"); - Walk(codeLabel); - } - - Header.Triggers = triggers - .Select( - it => new Trigger - { - Addr = it.Addr.ToString(), - Key = it.Key, - } - ) - .ToArray(); - - var revealed = new List(); - - for (int addr = firstAddr; addr < read.Length / 2 - 8; addr++) - { - if (addrAnnotated.ContainsKey(addr)) - { - continue; - } - - read.Position = 16 + 2 * addr; - var dataWord = read.ReadUInt16(); - - addrAnnotated[addr] = new IndeterminateContent(dataWord); - - if (addrAnnotated.TryGetValue(addr - 1, out var prevAnnot) && prevAnnot is not IndeterminateContent prevWord) - { - AddAddr(addr, $"D{addr}"); - } - } - - var firstTextPoolAddr = FindFirstTextPoolAddr(addrAnnotated); - - { - // resolve strings - - var dataList = addrAnnotated - .Where(pair => pair.Value is IndeterminateContent) - .ToList(); - - while (dataList.Any()) - { - var baseAddr = dataList[0].Key; - - if (firstTextPoolAddr <= baseAddr) - { - int numContinuous = 1; - while (true) - { - if (true - && numContinuous < dataList.Count - && dataList[numContinuous].Value is IndeterminateContent - && dataList[numContinuous].Key == baseAddr + numContinuous - ) - { - numContinuous += 1; - continue; - } - else - { - break; - } - } - - if (numContinuous >= 2) - { - var bytes = new byte[2 * numContinuous]; - for (int x = 0; x < numContinuous; x++) - { - var word = ((IndeterminateContent)dataList[x].Value).Word; - bytes[2 * x + 0] = (byte)(word); - bytes[2 * x + 1] = (byte)(word >> 8); - } - - static (int numValidWords, IAnnotation? annot) TryToDecode(byte[] bytes) - { - for (int x = 0; x < bytes.Length; x++) - { - if (bytes[x] == 0) - { - if (x < 1) - { - // The length is not enough to decide this is a text. - break; - } - if ((x & 1) == 0) - { - x++; - } - - // This is a valid text - return ( - (x + 1) / 2, - new TextContent(Encoding.ASCII.GetString(bytes, 0, x + 1)) - ); - } - if (IsValidChar(bytes[x])) - { - // A valid char - continue; - } - else - { - // An invalid char - break; - } - } - - // No valid text found - return (0, null); - } - - var (numValidWords, annot) = TryToDecode(bytes); - - if (1 <= numValidWords && annot != null) - { - dataList.RemoveRange(0, numValidWords); - for (int x = 0; x < numValidWords; x++) - { - if (x == 0) - { - AddAddr(baseAddr + x, $"TXT{baseAddr + x}"); - addrAnnotated[baseAddr + x] = annot; - } - else - { - addrAnnotated[baseAddr + x] = TextPart.Value; - } - } - continue; - } - } - } - - dataList.RemoveAt(0); - } - } - - if (codeRevealer) - { - while (true) - { - var firstIndeterminate = addrAnnotated - .FirstOrDefault( - pair => true - && pair.Key < firstTextPoolAddr - && pair.Value is IndeterminateContent - ); - - // KeyValuePair is struct (value) and it cannot be null. While Value is null-able instead. - - if (firstIndeterminate.Value == null) - { - break; - } - - var addr = firstIndeterminate.Key; - - addrAnnotated.Remove(firstIndeterminate.Key); - - AddAddr(addr, $"L{addr}"); - Walk(addr); - - revealed.Add(addr); - } - } - - if (codeRevealerLabeling) - { - foreach (var pair in addrAnnotated.ToArray()) - { - if (pair.Value is CodeContent content) - { - if (content.Desc.CodeRevealerLabeling - && content.Args.Length == 1 - && content.Args[0] is ParsedArg arg - && arg.Label == null - && arg.Value != 0 - ) - { - if (revealed.Contains(arg.Value)) - { - content.Args[0].Label = $"L{arg.Value}"; - content.Args[0].AddrRef = arg.Value; - } - } - } - } - } - - { - foreach (var pair in addrAnnotated.ToArray()) - { - if (pair.Value is IndeterminateContent indeterminate) - { - addrAnnotated[pair.Key] = new WordContent(indeterminate.Word); - } - } - } - - topComment = string.Join("\n" - , $"{nameof(codeLabels)}: {((codeLabels != null) ? string.Join(" ", codeLabels.Select(it => $"-l {it}")) : "")}" - , $"{nameof(codeRevealer)}: {((revealed != null) ? string.Join(" ", revealed.Select(it => $"-l {it}")) : "")}" - ); - - AddressAnnotated = addrAnnotated; - AddressLabels = addrLabels; - AddressComments = addrComments; - AddressCodeComments = addrCodeComments; - WorkLabels = workLabels; - TopComment = topComment; - } - - private static int FindFirstTextPoolAddr(IDictionary addrAnnotated) - { - var firstTextPoolAddr = int.MaxValue; - - var dataPairs = addrAnnotated - .OrderByDescending(pair => pair.Key) - .Where(pair => pair.Value is IndeterminateContent); - - if (dataPairs.Any()) - { - foreach (var pair in dataPairs) - { - var content = (IndeterminateContent)pair.Value; - var bytes = new byte[] { (byte)(content.Word), (byte)(content.Word >> 8) }; - if (true - && (bytes[0] == 0 || IsValidChar(bytes[0])) - && (bytes[1] == 0 || IsValidChar(bytes[1])) - ) - { - firstTextPoolAddr = pair.Key; - continue; - } - else - { - break; - } - } - } - - return firstTextPoolAddr; - } - - private static bool IsValidChar(byte v) - { - var chr = (char)v; - return 32 <= chr && chr <= 126; - } - - public interface IAnnotation - { - - } - - public class ParsedArg - { - public string? Label { get; set; } - public int Value { get; set; } - public int? AddrRef { get; set; } - public bool PreferFloat32 { get; set; } - } - - public sealed class CodeContent : IAnnotation - { - public CodeContent(BdxInstructionDesc desc) - { - Desc = desc; - } - - public BdxInstructionDesc Desc { get; set; } - public ParsedArg[] Args { get; set; } = new ParsedArg[0]; - - public override string ToString() => Desc?.ToString() ?? "?"; - } - - public sealed class CodeArg : IAnnotation - { - private CodeArg() - { - - } - - public override string ToString() => $"CodeArg"; - - public static readonly CodeArg Value = new CodeArg(); - } - - public sealed class IndeterminateContent : IAnnotation - { - public ushort Word { get; set; } - - public IndeterminateContent(ushort word) - { - Word = word; - } - - public override string ToString() => $"Indeterminate"; - } - - public sealed class WordContent : IAnnotation - { - public ushort Word { get; set; } - - public WordContent(ushort word) - { - Word = word; - } - - public override string ToString() => $"Word"; - } - - public sealed class TextContent : IAnnotation - { - public string Text { get; set; } - - public TextContent(string text) - { - Text = text; - } - - public override string ToString() => $"Text: {Text}"; - } - - public sealed class TextPart : IAnnotation - { - private TextPart() - { - - } - - public override string ToString() => $"TextPart"; - - public static readonly TextPart Value = new TextPart(); - } - - public static class TextFormatter - { - private static ISerializer ser = new SerializerBuilder() - .Build(); - - public static string Format(BdxDecoder decoder) - { - if (decoder.Header.IsEmpty) - { - var empty = new StringWriter(); - empty.WriteLine("---"); - empty.WriteLine("---"); - return empty.ToString(); - } - - var writer = new StringWriter(); - - writer.WriteLine("---"); - writer.WriteLine( - ser - .Serialize( - new BdxHeader - { - Name = decoder.Header.Name, - WorkSize = decoder.Header.WorkSize, - StackSize = decoder.Header.StackSize, - TempSize = decoder.Header.TempSize, - Triggers = decoder.Header.Triggers - .Select( - it => - { - if (int.TryParse(it.Addr, out int addr)) - { - decoder.AddressLabels.TryGetValue(addr, out string? labels); - - return new Trigger - { - Key = it.Key, - Addr = ((labels != null) ? labels.Split(',')[0] : it.Addr), - }; - } - else - { - return new Trigger - { - Key = it.Key, - Addr = it.Addr, - }; - } - } - ) - .ToArray(), - } - ) - ); - writer.WriteLine("---"); - - { - if (!string.IsNullOrEmpty(decoder.TopComment)) - { - foreach (var comment in decoder.TopComment.Split('\n')) - { - writer.WriteLine($"; {comment}"); - } - } - } - - writer.WriteLine(" section .text"); - - foreach (var line in decoder.AddressAnnotated) - { - if (decoder.AddressComments.TryGetValue(line.Key, out var commentBody) && commentBody != null) - { - foreach (var comment in commentBody.Replace("\r\n", "\n").Split('\n')) - { - writer.WriteLine($" ; {comment}"); - } - } - - if (decoder.AddressLabels.TryGetValue(line.Key, out string? labels) && labels != null) - { - foreach (var label in labels.Split(',')) - { - writer.WriteLine($"{label}:"); - } - } - - if (line.Value is CodeContent code) - { - if (decoder.AddressCodeComments.TryGetValue(line.Key, out string? commentPart)) - { - commentPart = " ; " + commentPart; - } - - writer.WriteLine($" {code.Desc.Name} {string.Join(", ", code.Args.Select(FormatArg))}{commentPart}"); - } - else if (line.Value is WordContent data) - { - writer.WriteLine($" dw 0x{data.Word:X4}"); - } - else if (line.Value is TextContent text) - { - writer.WriteLine($" db {MakeDbBody(text.Text)}"); - } - } - - if (decoder.Header.WorkSize != 0) - { - writer.WriteLine(); - writer.WriteLine(" section .bss"); - if (decoder.WorkLabels.Any()) - { - int lastPos = 0; - foreach (var workLabel in decoder.WorkLabels) - { - var thisPos = workLabel.Key; - if (lastPos < thisPos) - { - writer.WriteLine($" resb {thisPos - lastPos}"); - lastPos = thisPos; - } - writer.WriteLine($"{workLabel.Value}:"); - } - { - var thisPos = decoder.Header.WorkSize; - if (lastPos < thisPos) - { - writer.WriteLine($" resb {thisPos - lastPos}"); - } - } - } - else - { - writer.WriteLine($" resb {decoder.Header.WorkSize}"); - } - } - - return writer.ToString(); - } - - private static string FormatArg(ParsedArg arg) - { - if (arg.Label != null) - { - return $"{arg.Label}"; //offset - } - else if (arg.PreferFloat32) - { - return BitConverter.ToSingle(BitConverter.GetBytes(arg.Value)).ToString("R", invariantNumberFormat); - } - else - { - return arg.Value.ToString(); - } - } - - private static string MakeDbBody(string text) - { - var bytes = Encoding.ASCII.GetBytes(text); - - bool IsPrint(byte b) => 0x20 <= b && b <= 0x7E && b != 0x27 && b != 0x5C; - - var tokens = new List(); - - for (int x = 0, cx = bytes.Length; x < cx;) - { - { - int from = x; - while (x < cx && IsPrint(bytes[x])) - { - x++; - } - if (from != x) - { - tokens.Add("'" + Encoding.ASCII.GetString(bytes, from, x - from) + "'"); - } - } - - { - int from = x; - while (x < cx && !IsPrint(bytes[x])) - { - x++; - } - if (from != x) - { - for (; from < x; from++) - { - tokens.Add(bytes[from].ToString()); - } - } - } - } - - return string.Join(",", tokens); - } - } - - private static readonly IFormatProvider invariantNumberFormat = CultureInfo.InvariantCulture.NumberFormat; - } -} +using OpenKh.Common; +using OpenKh.Kh2.Bdx.Models; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using Xe.BinaryMapper; +using YamlDotNet.Serialization; +using static OpenKh.Kh2.Bdx.Models.BdxHeader; + +namespace OpenKh.Kh2.Bdx.Utils +{ + public class BdxDecoder + { + public BdxHeader Header { get; } + + public IDictionary AddressAnnotated { get; } + public IDictionary AddressLabels { get; } + public IDictionary AddressComments { get; } + public IDictionary AddressCodeComments { get; } + public IDictionary WorkLabels { get; } + public string TopComment { get; set; } + + public BdxDecoder(Stream read, int[]? codeLabels = null, bool codeRevealer = false, bool codeRevealerLabeling = false) + { + if (read.Length == 0) + { + Header = new BdxHeader { IsEmpty = true }; + AddressAnnotated = new Dictionary(); + AddressLabels = new Dictionary(); + AddressComments = new Dictionary(); + AddressCodeComments = new Dictionary(); + WorkLabels = new Dictionary(); + TopComment = ""; + return; + } + + Header = BinaryMapping.ReadObject(read); + + var triggers = new List(); + while (true) + { + var one = BinaryMapping.ReadObject(read); + if (one.Key == 0 && one.Addr == 0) + { + break; + } + triggers.Add(one); + } + + int firstAddr = (12 + 8 * (triggers.Count + 1)) / 2; + + var addrAnnotated = new SortedDictionary(); + var addrLabels = new SortedDictionary(); + var addrComments = new SortedDictionary(); + var addrCodeComments = new SortedDictionary(); + var workLabels = new SortedDictionary(); + var topComment = ""; + + void AddAddr(int entry, string label) + { + if (addrLabels.TryGetValue(entry, out string? existing) && existing != null) + { + addrLabels[entry] = string.Join(",", existing.Split(',').Append(label).Distinct()); + } + else + { + addrLabels[entry] = label; + } + } + + void Walk(int entry) + { + var topAddr = entry; + + while (true) + { + var needClearance = false; + + if (addrAnnotated.TryGetValue(entry, out var annotHere)) + { + if (annotHere is IndeterminateContent) + { + needClearance = true; + } + else + { + return; + } + } + + var newPos = 16 + 2 * entry; + if (read.Length <= newPos) + { + // bug? + break; + } + + read.Position = newPos; + var codeWord = read.ReadUInt16(); + + var desc = BdxInstructionDescs.FindByCode(codeWord); + if (desc == null) + { + break; + } + + var code = new CodeContent(desc); + + if (needClearance) + { + var overrideDetected = false; + int x = 1; + for (; x < desc.CodeSize; x++) + { + if (true + && addrAnnotated.TryGetValue(entry + x, out var codePartHit) + && codePartHit is not IndeterminateContent + ) + { + overrideDetected = true; + break; + } + + if (addrLabels.TryGetValue(entry + x, out var codePartLabels)) + { + overrideDetected = true; + break; + } + } + if (overrideDetected) + { + addrComments[entry] = $"Although L{entry + x} is in IndeterminateContent area (L{entry} to L{entry + desc.CodeSize - 1}), there is a collision with text data? Maybe codeRevealer problem. Possibly need more better bottom text pool detection."; + break; + } + } + + addrAnnotated[entry] = code; + + if (desc.NeverReturn || desc.IsGosubRet) + { + break; + } + + if (desc.Args != null) + { + var parsedArgs = new List(); + + foreach (var arg in desc.Args) + { + var parsedArg = new ParsedArg(); + + int argValue; + if (arg.Type == BdxInstructionDesc.ArgType.Imm16) + { + argValue = read.ReadInt16(); + } + else if (arg.Type == BdxInstructionDesc.ArgType.Imm32) + { + argValue = read.ReadInt32(); + } + else if (arg.Type == BdxInstructionDesc.ArgType.Float32) + { + argValue = read.ReadInt32(); + parsedArg.PreferFloat32 = true; + } + else + { + argValue = new BdxInstruction(codeWord).Ssub; + } + + + if (arg.IsRelative) + { + var nextEntry = (ushort)(entry + (desc.CodeSize) + argValue); + + parsedArg.Value = nextEntry; + parsedArg.AddrRef = nextEntry; + + if (desc.IsJump || desc.IsGosub) + { + var newLabel = $"L{nextEntry}"; + parsedArg.Label = newLabel; + AddAddr(nextEntry, newLabel); + Walk(nextEntry); + } + } + else if (arg.AiPos) + { + parsedArg.Value = (ushort)argValue; + + var newLabel = $"L{(ushort)argValue}"; + parsedArg.Label = newLabel; + AddAddr((ushort)argValue, newLabel); + } + else if (arg.WorkPos) + { + parsedArg.Value = (ushort)argValue; + + var newLabel = $"W{(ushort)argValue}"; + parsedArg.Label = newLabel; + workLabels[(ushort)argValue] = newLabel; + } + else + { + parsedArg.Value = argValue; + } + + parsedArgs.Add(parsedArg); + } + + if (desc.IsSyscall) + { + var tableIdx = new BdxInstruction(codeWord).Ssub; + var trapIdx = parsedArgs[1].Value; + var trap = BdxTraps.GetTraps() + .FirstOrDefault(it => it.TableIndex == tableIdx && it.TrapIndex == trapIdx); + addrCodeComments[entry] = (trap != null) + ? $"{trap.Name} ({trap.Flags & 65535} in, {(((trap.Flags & 0x40000000) != 0) ? 1 : 0)} out)" + : "?"; + } + + code.Args = parsedArgs.ToArray(); + } + + for (int x = 1; x < desc.CodeSize; x++) + { + addrAnnotated[entry + x] = CodeArg.Value; + } + + if (desc.IsJump && !desc.IsJumpConditional) + { + break; + } + + entry += desc.CodeSize; + } + } + + var knownItems = BdxTrigger.GetKnownItems() + .ToDictionary( + one => one.Key, + one => one.Label + ); + + string GetTriggerLabelFor(int key) + { + if (knownItems.TryGetValue(key, out string? label) && label != null) + { + return label; + } + else + { + return $"TR{key}"; + } + } + + foreach (var trigger in triggers) + { + AddAddr(trigger.Addr, GetTriggerLabelFor(trigger.Key)); + Walk(trigger.Addr); + } + + foreach (var codeLabel in codeLabels ?? new int[0]) + { + AddAddr(codeLabel, $"L{codeLabel}"); + Walk(codeLabel); + } + + Header.Triggers = triggers + .Select( + it => new Trigger + { + Addr = it.Addr.ToString(), + Key = it.Key, + } + ) + .ToArray(); + + var revealed = new List(); + + for (int addr = firstAddr; addr < read.Length / 2 - 8; addr++) + { + if (addrAnnotated.ContainsKey(addr)) + { + continue; + } + + read.Position = 16 + 2 * addr; + var dataWord = read.ReadUInt16(); + + addrAnnotated[addr] = new IndeterminateContent(dataWord); + + if (addrAnnotated.TryGetValue(addr - 1, out var prevAnnot) && prevAnnot is not IndeterminateContent prevWord) + { + AddAddr(addr, $"D{addr}"); + } + } + + var firstTextPoolAddr = FindFirstTextPoolAddr(addrAnnotated); + + { + // resolve strings + + var dataList = addrAnnotated + .Where(pair => pair.Value is IndeterminateContent) + .ToList(); + + while (dataList.Any()) + { + var baseAddr = dataList[0].Key; + + if (firstTextPoolAddr <= baseAddr) + { + int numContinuous = 1; + while (true) + { + if (true + && numContinuous < dataList.Count + && dataList[numContinuous].Value is IndeterminateContent + && dataList[numContinuous].Key == baseAddr + numContinuous + ) + { + numContinuous += 1; + continue; + } + else + { + break; + } + } + + if (numContinuous >= 2) + { + var bytes = new byte[2 * numContinuous]; + for (int x = 0; x < numContinuous; x++) + { + var word = ((IndeterminateContent)dataList[x].Value).Word; + bytes[2 * x + 0] = (byte)(word); + bytes[2 * x + 1] = (byte)(word >> 8); + } + + static (int numValidWords, IAnnotation? annot) TryToDecode(byte[] bytes) + { + for (int x = 0; x < bytes.Length; x++) + { + if (bytes[x] == 0) + { + if (x < 1) + { + // The length is not enough to decide this is a text. + break; + } + if ((x & 1) == 0) + { + x++; + } + + // This is a valid text + return ( + (x + 1) / 2, + new TextContent(Encoding.ASCII.GetString(bytes, 0, x + 1)) + ); + } + if (IsValidChar(bytes[x])) + { + // A valid char + continue; + } + else + { + // An invalid char + break; + } + } + + // No valid text found + return (0, null); + } + + var (numValidWords, annot) = TryToDecode(bytes); + + if (1 <= numValidWords && annot != null) + { + dataList.RemoveRange(0, numValidWords); + for (int x = 0; x < numValidWords; x++) + { + if (x == 0) + { + AddAddr(baseAddr + x, $"TXT{baseAddr + x}"); + addrAnnotated[baseAddr + x] = annot; + } + else + { + addrAnnotated[baseAddr + x] = TextPart.Value; + } + } + continue; + } + } + } + + dataList.RemoveAt(0); + } + } + + if (codeRevealer) + { + while (true) + { + var firstIndeterminate = addrAnnotated + .FirstOrDefault( + pair => true + && pair.Key < firstTextPoolAddr + && pair.Value is IndeterminateContent + ); + + // KeyValuePair is struct (value) and it cannot be null. While Value is null-able instead. + + if (firstIndeterminate.Value == null) + { + break; + } + + var addr = firstIndeterminate.Key; + + addrAnnotated.Remove(firstIndeterminate.Key); + + AddAddr(addr, $"L{addr}"); + Walk(addr); + + revealed.Add(addr); + } + } + + if (codeRevealerLabeling) + { + foreach (var pair in addrAnnotated.ToArray()) + { + if (pair.Value is CodeContent content) + { + if (content.Desc.CodeRevealerLabeling + && content.Args.Length == 1 + && content.Args[0] is ParsedArg arg + && arg.Label == null + && arg.Value != 0 + ) + { + if (revealed.Contains(arg.Value)) + { + content.Args[0].Label = $"L{arg.Value}"; + content.Args[0].AddrRef = arg.Value; + } + } + } + } + } + + { + foreach (var pair in addrAnnotated.ToArray()) + { + if (pair.Value is IndeterminateContent indeterminate) + { + addrAnnotated[pair.Key] = new WordContent(indeterminate.Word); + } + } + } + + topComment = string.Join("\n" + , $"{nameof(codeLabels)}: {((codeLabels != null) ? string.Join(" ", codeLabels.Select(it => $"-l {it}")) : "")}" + , $"{nameof(codeRevealer)}: {((revealed != null) ? string.Join(" ", revealed.Select(it => $"-l {it}")) : "")}" + ); + + AddressAnnotated = addrAnnotated; + AddressLabels = addrLabels; + AddressComments = addrComments; + AddressCodeComments = addrCodeComments; + WorkLabels = workLabels; + TopComment = topComment; + } + + private static int FindFirstTextPoolAddr(IDictionary addrAnnotated) + { + var firstTextPoolAddr = int.MaxValue; + + var dataPairs = addrAnnotated + .OrderByDescending(pair => pair.Key) + .Where(pair => pair.Value is IndeterminateContent); + + if (dataPairs.Any()) + { + foreach (var pair in dataPairs) + { + var content = (IndeterminateContent)pair.Value; + var bytes = new byte[] { (byte)(content.Word), (byte)(content.Word >> 8) }; + if (true + && (bytes[0] == 0 || IsValidChar(bytes[0])) + && (bytes[1] == 0 || IsValidChar(bytes[1])) + ) + { + firstTextPoolAddr = pair.Key; + continue; + } + else + { + break; + } + } + } + + return firstTextPoolAddr; + } + + private static bool IsValidChar(byte v) + { + var chr = (char)v; + return 32 <= chr && chr <= 126; + } + + public interface IAnnotation + { + + } + + public class ParsedArg + { + public string? Label { get; set; } + public int Value { get; set; } + public int? AddrRef { get; set; } + public bool PreferFloat32 { get; set; } + } + + public sealed class CodeContent : IAnnotation + { + public CodeContent(BdxInstructionDesc desc) + { + Desc = desc; + } + + public BdxInstructionDesc Desc { get; set; } + public ParsedArg[] Args { get; set; } = new ParsedArg[0]; + + public override string ToString() => Desc?.ToString() ?? "?"; + } + + public sealed class CodeArg : IAnnotation + { + private CodeArg() + { + + } + + public override string ToString() => $"CodeArg"; + + public static readonly CodeArg Value = new CodeArg(); + } + + public sealed class IndeterminateContent : IAnnotation + { + public ushort Word { get; set; } + + public IndeterminateContent(ushort word) + { + Word = word; + } + + public override string ToString() => $"Indeterminate"; + } + + public sealed class WordContent : IAnnotation + { + public ushort Word { get; set; } + + public WordContent(ushort word) + { + Word = word; + } + + public override string ToString() => $"Word"; + } + + public sealed class TextContent : IAnnotation + { + public string Text { get; set; } + + public TextContent(string text) + { + Text = text; + } + + public override string ToString() => $"Text: {Text}"; + } + + public sealed class TextPart : IAnnotation + { + private TextPart() + { + + } + + public override string ToString() => $"TextPart"; + + public static readonly TextPart Value = new TextPart(); + } + + public static class TextFormatter + { + private static ISerializer ser = new SerializerBuilder() + .Build(); + + public static string Format(BdxDecoder decoder) + { + if (decoder.Header.IsEmpty) + { + var empty = new StringWriter(); + empty.WriteLine("---"); + empty.WriteLine("---"); + return empty.ToString(); + } + + var writer = new StringWriter(); + + writer.WriteLine("---"); + writer.WriteLine( + ser + .Serialize( + new BdxHeader + { + Name = decoder.Header.Name, + WorkSize = decoder.Header.WorkSize, + StackSize = decoder.Header.StackSize, + TempSize = decoder.Header.TempSize, + Triggers = decoder.Header.Triggers + .Select( + it => + { + if (int.TryParse(it.Addr, out int addr)) + { + decoder.AddressLabels.TryGetValue(addr, out string? labels); + + return new Trigger + { + Key = it.Key, + Addr = ((labels != null) ? labels.Split(',')[0] : it.Addr), + }; + } + else + { + return new Trigger + { + Key = it.Key, + Addr = it.Addr, + }; + } + } + ) + .ToArray(), + } + ) + ); + writer.WriteLine("---"); + + { + if (!string.IsNullOrEmpty(decoder.TopComment)) + { + foreach (var comment in decoder.TopComment.Split('\n')) + { + writer.WriteLine($"; {comment}"); + } + } + } + + writer.WriteLine(" section .text"); + + foreach (var line in decoder.AddressAnnotated) + { + if (decoder.AddressComments.TryGetValue(line.Key, out var commentBody) && commentBody != null) + { + foreach (var comment in commentBody.Replace("\r\n", "\n").Split('\n')) + { + writer.WriteLine($" ; {comment}"); + } + } + + if (decoder.AddressLabels.TryGetValue(line.Key, out string? labels) && labels != null) + { + foreach (var label in labels.Split(',')) + { + writer.WriteLine($"{label}:"); + } + } + + if (line.Value is CodeContent code) + { + if (decoder.AddressCodeComments.TryGetValue(line.Key, out string? commentPart)) + { + commentPart = " ; " + commentPart; + } + + writer.WriteLine($" {code.Desc.Name} {string.Join(", ", code.Args.Select(FormatArg))}{commentPart}"); + } + else if (line.Value is WordContent data) + { + writer.WriteLine($" dw 0x{data.Word:X4}"); + } + else if (line.Value is TextContent text) + { + writer.WriteLine($" db {MakeDbBody(text.Text)}"); + } + } + + if (decoder.Header.WorkSize != 0) + { + writer.WriteLine(); + writer.WriteLine(" section .bss"); + if (decoder.WorkLabels.Any()) + { + int lastPos = 0; + foreach (var workLabel in decoder.WorkLabels) + { + var thisPos = workLabel.Key; + if (lastPos < thisPos) + { + writer.WriteLine($" resb {thisPos - lastPos}"); + lastPos = thisPos; + } + writer.WriteLine($"{workLabel.Value}:"); + } + { + var thisPos = decoder.Header.WorkSize; + if (lastPos < thisPos) + { + writer.WriteLine($" resb {thisPos - lastPos}"); + } + } + } + else + { + writer.WriteLine($" resb {decoder.Header.WorkSize}"); + } + } + + return writer.ToString(); + } + + private static string FormatArg(ParsedArg arg) + { + if (arg.Label != null) + { + return $"{arg.Label}"; //offset + } + else if (arg.PreferFloat32) + { + return BitConverter.ToSingle(BitConverter.GetBytes(arg.Value)).ToString("R", invariantNumberFormat); + } + else + { + return arg.Value.ToString(); + } + } + + private static string MakeDbBody(string text) + { + var bytes = Encoding.ASCII.GetBytes(text); + + bool IsPrint(byte b) => 0x20 <= b && b <= 0x7E && b != 0x27 && b != 0x5C; + + var tokens = new List(); + + for (int x = 0, cx = bytes.Length; x < cx;) + { + { + int from = x; + while (x < cx && IsPrint(bytes[x])) + { + x++; + } + if (from != x) + { + tokens.Add("'" + Encoding.ASCII.GetString(bytes, from, x - from) + "'"); + } + } + + { + int from = x; + while (x < cx && !IsPrint(bytes[x])) + { + x++; + } + if (from != x) + { + for (; from < x; from++) + { + tokens.Add(bytes[from].ToString()); + } + } + } + } + + return string.Join(",", tokens); + } + } + + private static readonly IFormatProvider invariantNumberFormat = CultureInfo.InvariantCulture.NumberFormat; + } +} diff --git a/OpenKh.Command.Bdxio/Utils/BdxEncoder.cs b/OpenKh.Kh2/Bdx/Utils/BdxEncoder.cs similarity index 97% rename from OpenKh.Command.Bdxio/Utils/BdxEncoder.cs rename to OpenKh.Kh2/Bdx/Utils/BdxEncoder.cs index 3fe1c1445..6dec2c14e 100644 --- a/OpenKh.Command.Bdxio/Utils/BdxEncoder.cs +++ b/OpenKh.Kh2/Bdx/Utils/BdxEncoder.cs @@ -1,866 +1,867 @@ -using Antlr4.Runtime; -using Antlr4.Runtime.Tree; -using NLog; -using OpenKh.Command.Bdxio.Models; -using System.Globalization; -using System.Text; -using Xe.BinaryMapper; -using static BdxScriptParser; -using static OpenKh.Command.Bdxio.Models.BdxHeader; -using static OpenKh.Command.Bdxio.Models.BdxInstructionDesc; - -namespace OpenKh.Command.Bdxio.Utils -{ - public class BdxEncoder - { - public byte[] Content { get; } = new byte[0]; - - public BdxEncoder( - BdxHeader header, - string script, - string scriptName, - Func loadScript - ) - { - var logger = LogManager.GetLogger("BdxEncoder"); - - if (string.IsNullOrWhiteSpace(script) && header.IsEmpty) - { - return; - } - - var labels = new SortedDictionary(); - - var instructionDict = new (string, BdxInstructionDesc)[0] - .Concat( - BdxInstructionDescs.GetDescs() - .Select(desc => (desc.Name, desc)) - ) - .Concat( - BdxInstructionDescs.GetDescs() - .SelectMany( - desc => desc.OldNames - .Select( - oldName => (oldName, desc) - ) - ) - ) - .GroupBy(pair => pair.Item1) - .Select(it => it.First()) - .ToDictionary(it => it.Item1, it => it.Item2); - - Func ResolveInt32Factory( - Func stringToInt32, - Func, int> labelToInt32 - ) - { - return (ArgContext argContext, CompilePass pass) => - { - if (pass.First) - { - return 0; - } - else - { - if (argContext.numberdata() is NumberdataContext numberdata) - { - return stringToInt32(numberdata); - } - else if (argContext.id() is IdContext id) - { - var name = id.GetText(); - return labelToInt32(name, () => id.Start); - } - else - { - throw new InvalidDataException($"{FormatLineColumn(argContext.Start)} Unknown arg!"); - } - } - }; - } - - int LabelToInt32Converter(string name, Func getStart) - { - if (!labels.TryGetValue(name, out var any) || any == null) - { - throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} not found")); - } - - if (any is CodeLabel label) - { - return label.PC; - } - else if (any is ConstLabel constLabel) - { - return constLabel.Value; - } - else if (any is BssLabel bssLabel) - { - return bssLabel.ByteOffset; - } - - throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} cannot be used here")); - } - - float LabelToFloat32Converter(string name, Func getStart) - { - if (!labels.TryGetValue(name, out var any) || any == null) - { - throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} not found")); - } - - if (any is ConstLabel constLabel) - { - return constLabel.Value; - } - - throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} cannot be used here")); - } - - Func ResolveFloat32Factory( - Func, float> labelToFloat32 - ) - { - return (ArgContext argContext, CompilePass pass) => - { - if (pass.First) - { - return 0; - } - else - { - if (argContext.numberdata() is NumberdataContext numberdata) - { - return float.Parse(numberdata.GetText(), invariantNumberFormat); - } - else if (argContext.id() is IdContext id) - { - var name = id.GetText(); - return labelToFloat32(name, () => id.Start); - } - else - { - throw new InvalidDataException($"{FormatLineColumn(argContext.Start)} Unknown arg!"); - } - } - }; - } - - var resolveInt32ForIntTrigger = ResolveInt32Factory( - stringToInt32: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), - labelToInt32: LabelToInt32Converter - ); - - var resolveInt32ForSsub = ResolveInt32Factory( - stringToInt32: Helper.AllowedRangeFactory( - factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), - min: -2048, - max: 4095 - ), - labelToInt32: LabelToInt32Converter - ); - - var resolveInt32ForRelativeImm16 = ResolveInt32Factory( - stringToInt32: Helper.AllowedRangeFactory( - factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), - min: short.MinValue, - max: short.MaxValue - ), - labelToInt32: LabelToInt32Converter - ); - - var resolveInt32ForValueImm16 = ResolveInt32Factory( - stringToInt32: Helper.AllowedRangeFactory( - factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), - min: short.MinValue, - max: ushort.MaxValue - ), - labelToInt32: LabelToInt32Converter - ); - - var resolveInt32ForRelativeImm32 = ResolveInt32Factory( - stringToInt32: Helper.AllowedRangeFactory( - factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), - min: int.MinValue, - max: int.MaxValue - ), - labelToInt32: LabelToInt32Converter - ); - - var resolveInt32ForValueImm32 = ResolveInt32Factory( - stringToInt32: Helper.AllowedRangeFactory( - factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: true), - min: int.MinValue, - max: int.MaxValue - ), - labelToInt32: LabelToInt32Converter - ); - - var resolveFloat32ForValueFloat32 = ResolveFloat32Factory( - labelToFloat32: LabelToFloat32Converter - ); - - int lastBssBytes = 0; - - var compilePasses = new CompilePass[] { - new CompilePass(Index: 0, First: true, Last: false), // resolve code placement and labels offset - new CompilePass(Index: 1, First: false, Last: false), // resolve equ (const) - new CompilePass(Index: 2, First: false, Last: true), // compile - }; - - foreach (var pass in compilePasses) - { - var words = new MemoryStream(); - - void WordAlignment() - { - if ((words.Length & 1) != 0) - { - words.WriteByte(0); - } - } - - BinaryMapping.WriteObject(words, header); - - if (!pass.First) - { - if (header.WorkSize < lastBssBytes) - { - logger.Warn($"WorkSize {header.WorkSize} is extended to {lastBssBytes}"); - - words.Position = 16; - words.Write(BitConverter.GetBytes(lastBssBytes)); - words.Seek(0, SeekOrigin.End); - } - } - - foreach (var intTrigger in header.Triggers - .Select( - item => - { - return new IntTrigger - { - Key = item.Key, - Addr = resolveInt32ForIntTrigger(Helper.ParseAsArg(item.Addr), pass), - }; - } - ) - ) - { - BinaryMapping.WriteObject(words, intTrigger); - } - - BinaryMapping.WriteObject(words, new IntTrigger { Addr = 0, Key = 0, }); - - var codeSeg = new CodeSegment(words); - var bssSeg = new BssSegment(); - ISegment segment = codeSeg; - - void AddLabel(string labelName, ILabel labelValue, Func getTokenPos) - { - if (pass.First) - { - if (!labels.TryAdd(labelName, labelValue)) - { - throw new InvalidDataException($"{FormatLineColumn(getTokenPos().Start)} Redefine of label {labelName}"); - } - } - else - { - labels[labelName] = labelValue; - } - } - - void WalkStatements(ProgContext root) - { - foreach (var st in root.statement()) - { - //var pc = (int)(words.Length / 2 - 8); - - if (st.section() is SectionContext section) - { - var id = section.section_id(); - var sectionName = id.GetText(); - if (sectionName == ".text") - { - segment = codeSeg; - } - else if (sectionName == ".bss") - { - segment = bssSeg; - } - else - { - throw new InvalidDataException($"{FormatLineColumn(id.Start)} Unknown section name {sectionName}"); - } - continue; - } - else if (st.equ() is EquContext equ) - { - var intValue = Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false).Invoke(equ.numberdata()); - - AddLabel( - equ.name.GetText(), - new ConstLabel { Value = intValue, }, - () => equ.name - ); - } - - if (st.label() is LabelContext label) - { - WordAlignment(); - var id = label.id(); - AddLabel( - id.GetText(), - segment.GetLabel(), - () => id - ); - } - - if (st.order() is OrderContext order) - { - if (order.db() is DbContext db) - { - foreach (var byteData in db.bytedata()) - { - if (byteData.numberdata() is NumberdataContext numberData) - { - segment.WriteByte(Helper.GetAsByte(numberData)); - } - else if (byteData.StringData() is ITerminalNode stringData) - { - var text = stringData.GetText(); - var bytes = Encoding.ASCII.GetBytes(text.Substring(1, text.Length - 2)); - segment.Write(bytes); - } - else if (byteData.id() is IdContext id) - { - var value = pass.First ? 0 : LabelToInt32Converter(id.GetText(), () => id.Start); - segment.WriteByte((byte)value); - } - else - { - throw new InvalidDataException($"{FormatLineColumn(byteData.Start)} Unknown byte data!"); - } - } - } - else if (order.resb() is ResbContext resb) - { - if (resb.numberdata() is NumberdataContext numberdata) - { - var numBytes = Helper.GetAsInt32(numberdata); - segment.AllocateBytes(numBytes); - } - else if (resb.id() is IdContext id) - { - var numBytes = LimitInt32Range( - pass.First - ? 0 - : LabelToInt32Converter(id.GetText(), () => id.Start), - min: int.MinValue, - max: int.MaxValue, - getStart: () => id.Start - ); - segment.AllocateBytes(numBytes); - } - } - else if (order.dw() is DwContext dw) - { - WordAlignment(); - foreach (var wordData in dw.worddata()) - { - if (wordData.numberdata() is NumberdataContext numberdata) - { - segment.Write(BitConverter.GetBytes(Helper.GetAsUInt16(numberdata))); - } - else if (wordData.id() is IdContext id) - { - var value = (ushort)LimitInt32Range(pass.First ? 0 : LabelToInt32Converter(id.GetText(), () => id.Start), min: -127, max: 255, () => id.Start); - segment.Write(BitConverter.GetBytes(value)); - } - else - { - throw new InvalidDataException($"{FormatLineColumn(wordData.Start)} Unknown word data!"); - } - } - } - else if (order.resw() is ReswContext resw) - { - if (resw.numberdata() is NumberdataContext numberdata) - { - var numBytes = 2 * Helper.GetAsInt32(numberdata); - segment.AllocateBytes(numBytes); - } - else if (resw.id() is IdContext id) - { - var numBytes = 2 * LimitInt32Range(pass.First ? 0 : LabelToInt32Converter(id.GetText(), () => id.Start), min: int.MinValue, max: int.MaxValue, () => id.Start); - segment.AllocateBytes(numBytes); - } - } - else if (order.instruction() is InstructionContext instr) - { - var name = instr.id().GetText(); - if (!instructionDict.TryGetValue(name, out var desc)) - { - throw new InvalidDataException($"{FormatLineColumn(instr.Start)} Unknown instruction '{name}'!"); - } - - if (segment is not CodeSegment thisSegment) - { - throw new InvalidDataException($"{FormatLineColumn(instr.Start)} This must be placed at `section .text`!"); - } - - var pc = thisSegment.PC; - - var word = new BdxInstruction(desc.Code); - - var args = desc.Args ?? new Arg[0]; - - var instrArgs = instr.arg(); - - for (int x = 0; x < args.Length; x++) - { - if (args[x].Type == ArgType.Ssub) - { - word.Ssub = (ushort)resolveInt32ForSsub(instrArgs[x], pass); - } - } - - segment.Write(BitConverter.GetBytes(word.Code)); - - for (int x = 0; x < args.Length; x++) - { - if (args[x].Type == ArgType.Imm16) - { - if (args[x].IsRelative) - { - var baseOffset = -pc - desc.CodeSize; - - segment.Write(BitConverter.GetBytes((ushort)(baseOffset + resolveInt32ForRelativeImm16(instrArgs[x], pass)))); - } - else - { - segment.Write(BitConverter.GetBytes((ushort)(resolveInt32ForValueImm16(instrArgs[x], pass)))); - } - } - else if (args[x].Type == ArgType.Imm32) - { - if (args[x].IsRelative) - { - var baseOffset = -pc - desc.CodeSize; - - segment.Write(BitConverter.GetBytes((uint)(baseOffset + resolveInt32ForRelativeImm32(instrArgs[x], pass)))); - } - else - { - segment.Write(BitConverter.GetBytes((uint)(resolveInt32ForValueImm32(instrArgs[x], pass)))); - } - } - else if (args[x].Type == ArgType.Float32) - { - { - segment.Write(BitConverter.GetBytes((float)(resolveFloat32ForValueFloat32(instrArgs[x], pass)))); - } - } - } - } - else if (order.include() is IncludeContext include) - { - var scriptName = include.FileName().GetText().Trim('"'); - var subScript = loadScript(scriptName); - - var stream = FromString(subScript, scriptName); - var lexer = new BdxScriptLexer(stream); - var tokens = new CommonTokenStream(lexer); - var parser = new BdxScriptParser(tokens); - var subRoot = parser.prog(); - - WalkStatements(subRoot); - } - else - { - //throw new InvalidDataException("Unknown statement!"); - // maybe NL - } - } - } - } - - { - var stream = FromString(script, scriptName); - var lexer = new BdxScriptLexer(stream); - var tokens = new CommonTokenStream(lexer); - var parser = new BdxScriptParser(tokens); - var root = parser.prog(); - - WalkStatements(root); - } - - WordAlignment(); - - lastBssBytes = bssSeg.numBytes; - - if (pass.Last) - { - Content = words.ToArray(); - } - } - } - - private int LimitInt32Range(int value, int min, int max, Func getStart) - { - if (min <= value && value <= max) - { - return value; - } - - throw new ArgumentOutOfRangeException(FormatErrorMessage(getStart(), $"Integer must be in range of from {min} to {max}")); - } - - private static ICharStream FromString(string script, string sourceName) - { - var stream = CharStreams.fromString(script); - if (stream is CodePointCharStream charStream) - { - charStream.name = sourceName; - } - return stream; - } - - private static string FormatLineColumn(IToken start) => $"{start.InputStream.SourceName} line {start.Line}:{start.Column}"; - - private static string FormatErrorMessage(IToken start, IFormattable text) => $"{start.InputStream.SourceName} line {start.Line}:{start.Column} {text}"; - private static string FormatErrorMessage(IToken start, string text) => $"{start.InputStream.SourceName} line {start.Line}:{start.Column} {text}"; - - private static class Helper - { - internal static int GetAsInt32(NumberdataContext numberData) - { - var decimalNumber = numberData.decimalnumber; - if (decimalNumber != null) - { - var body = decimalNumber.Text; - - if (uint.TryParse(body, out uint uintVal)) - { - return (int)uintVal; - } - else if (int.TryParse(body, out int intVal)) - { - return intVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); - } - } - else if (numberData.hexnumber is IToken hexNumber) - { - var body = hexNumber.Text; - - if (uint.TryParse(body, NumberStyles.HexNumber, null, out uint uintVal)) - { - return (int)uintVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); - } - } - else if (numberData.floatnumber is IToken) - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); - } - else - { - throw new InvalidDataException($"{FormatLineColumn(numberData.Start)} Unknown number data!"); - } - } - - internal static ArgContext ParseAsArg(string addr) - { - var stream = CharStreams.fromString(addr); - var lexer = new BdxScriptLexer(stream); - var tokens = new CommonTokenStream(lexer); - var parser = new BdxScriptParser(tokens); - - return parser.arg(); - } - - internal static Func NumberdataContextToInt32OrFloat32ConverterFactory() - { - return (NumberdataContext numberData) => - { - var decimalNumber = numberData.decimalnumber; - if (decimalNumber != null) - { - var body = decimalNumber.Text; - - if (uint.TryParse(body, out uint uintVal)) - { - return (int)uintVal; - } - else if (int.TryParse(body, out int intVal)) - { - return intVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); - } - } - else if (numberData.hexnumber is IToken hexNumber) - { - var body = hexNumber.Text; - - if (uint.TryParse(body, NumberStyles.HexNumber, null, out uint uintVal)) - { - return (int)uintVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); - } - } - else if (numberData.floatnumber is IToken floatnumber) - { - var body = floatnumber.Text; - - if (float.TryParse(body, NumberStyles.HexNumber, invariantNumberFormat, out float floatVal)) - { - return (float)floatVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be float32 here")); - } - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Unknown number data!")); - } - }; - } - - internal static Func NumberdataContextToInt32ConverterFactory(bool allowFloat) - { - var func = NumberdataContextToInt32OrFloat32ConverterFactory(); - - return (NumberdataContext numberData) => - { - var value = func(numberData); - - if (value is int intValue) - { - return intValue; - } - else if (value is float floatValue) - { - if (!allowFloat) - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); - } - return BitConverter.ToInt32(BitConverter.GetBytes(floatValue)); - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Numeric converter bug")); - } - }; - } - - internal static Func AllowedRangeFactory(Func factory, int min, int max) - { - return (NumberdataContext numberData) => - { - var value = factory(numberData); - if (min <= value && value <= max) - { - return value; - } - - throw new ArgumentOutOfRangeException(FormatErrorMessage(numberData.Start, $"The value must be in range of from {min} to {max}!")); - }; - } - - internal static byte GetAsByte(NumberdataContext numberData) - { - var decimalNumber = numberData.decimalnumber; - if (decimalNumber != null) - { - var body = decimalNumber.Text; - - if (byte.TryParse(body, out byte byteVal)) - { - return byteVal; - } - else if (sbyte.TryParse(body, out sbyte sbyteVal)) - { - return (byte)sbyteVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be byte here")); - } - } - else if (numberData.hexnumber is IToken hexNumber) - { - var body = hexNumber.Text; - - if (byte.TryParse(body, NumberStyles.HexNumber, null, out byte byteVal)) - { - return byteVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be byte here")); - } - } - else if (numberData.floatnumber is IToken) - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Unknown number data!")); - } - } - - internal static ushort GetAsUInt16(NumberdataContext numberData) - { - var decimalNumber = numberData.decimalnumber; - if (decimalNumber != null) - { - var body = decimalNumber.Text; - - if (ushort.TryParse(body, out ushort ushortVal)) - { - return ushortVal; - } - else if (short.TryParse(body, out short shortVal)) - { - return (byte)shortVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int16 here")); - } - } - else if (numberData.hexnumber is IToken hexNumber) - { - var body = hexNumber.Text; - - if (ushort.TryParse(body, NumberStyles.HexNumber, null, out ushort ushortVal)) - { - return ushortVal; - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int16 here")); - } - } - else if (numberData.floatnumber is IToken) - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); - } - else - { - throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Unknown number data!")); - } - } - } - - private interface ISegment - { - void Write(byte[] bytes); - void WriteByte(byte value); - void AllocateBytes(int num); - ILabel GetLabel(); - } - - private class BssSegment : ISegment - { - public int numBytes = 0; - - public void AllocateBytes(int num) - { - numBytes += num; - } - - public ILabel GetLabel() - { - return new BssLabel { ByteOffset = numBytes }; - } - - public void Write(byte[] bytes) - { - throw new InvalidOperationException("`section .bss` cannot place static data. Use `resb 4` or `resw 2` or such."); - } - - public void WriteByte(byte value) - { - throw new InvalidOperationException("`section .bss` cannot place static data. Use `resb 4` or `resw 2` or such."); - } - } - - private class CodeSegment : ISegment - { - private readonly MemoryStream _words; - - public CodeSegment(MemoryStream words) - { - _words = words; - } - - public int PC => (int)(_words.Length / 2 - 8); - - public void AllocateBytes(int num) - { - _words.Write(new byte[num]); - } - - public ILabel GetLabel() - { - return new CodeLabel { PC = PC }; - } - - public void Write(byte[] buffer) - { - _words.Write(buffer); - } - - public void WriteByte(byte value) - { - _words.WriteByte(value); - } - } - - private interface ILabel - { - - } - - private class CodeLabel : ILabel - { - public int PC { get; set; } - } - - private class BssLabel : ILabel - { - public int ByteOffset { get; set; } - } - - private class ConstLabel : ILabel - { - public int Value { get; set; } - } - - private record CompilePass( - int Index, - bool First, - bool Last - ); - - private static readonly IFormatProvider invariantNumberFormat = CultureInfo.InvariantCulture.NumberFormat; - } -} +using Antlr4.Runtime; +using Antlr4.Runtime.Tree; +using NLog; +using OpenKh.Kh2.Bdx.Models; +using System; +using System.Globalization; +using System.IO; +using System.Text; +using Xe.BinaryMapper; +using static BdxScriptParser; +using static OpenKh.Kh2.Bdx.Models.BdxHeader; +using static OpenKh.Kh2.Bdx.Models.BdxInstructionDesc; +namespace OpenKh.Kh2.Bdx.Utils +{ + public class BdxEncoder + { + public byte[] Content { get; } = new byte[0]; + + public BdxEncoder( + BdxHeader header, + string script, + string scriptName, + Func loadScript + ) + { + var logger = LogManager.GetLogger("BdxEncoder"); + + if (string.IsNullOrWhiteSpace(script) && header.IsEmpty) + { + return; + } + + var labels = new SortedDictionary(); + + var instructionDict = new (string, BdxInstructionDesc)[0] + .Concat( + BdxInstructionDescs.GetDescs() + .Select(desc => (desc.Name, desc)) + ) + .Concat( + BdxInstructionDescs.GetDescs() + .SelectMany( + desc => desc.OldNames + .Select( + oldName => (oldName, desc) + ) + ) + ) + .GroupBy(pair => pair.Item1) + .Select(it => it.First()) + .ToDictionary(it => it.Item1, it => it.Item2); + + Func ResolveInt32Factory( + Func stringToInt32, + Func, int> labelToInt32 + ) + { + return (ArgContext argContext, CompilePass pass) => + { + if (pass.First) + { + return 0; + } + else + { + if (argContext.numberdata() is NumberdataContext numberdata) + { + return stringToInt32(numberdata); + } + else if (argContext.id() is IdContext id) + { + var name = id.GetText(); + return labelToInt32(name, () => id.Start); + } + else + { + throw new InvalidDataException($"{FormatLineColumn(argContext.Start)} Unknown arg!"); + } + } + }; + } + + int LabelToInt32Converter(string name, Func getStart) + { + if (!labels.TryGetValue(name, out var any) || any == null) + { + throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} not found")); + } + + if (any is CodeLabel label) + { + return label.PC; + } + else if (any is ConstLabel constLabel) + { + return constLabel.Value; + } + else if (any is BssLabel bssLabel) + { + return bssLabel.ByteOffset; + } + + throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} cannot be used here")); + } + + float LabelToFloat32Converter(string name, Func getStart) + { + if (!labels.TryGetValue(name, out var any) || any == null) + { + throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} not found")); + } + + if (any is ConstLabel constLabel) + { + return constLabel.Value; + } + + throw new ArgumentException(FormatErrorMessage(getStart(), $"Label {name} cannot be used here")); + } + + Func ResolveFloat32Factory( + Func, float> labelToFloat32 + ) + { + return (ArgContext argContext, CompilePass pass) => + { + if (pass.First) + { + return 0; + } + else + { + if (argContext.numberdata() is NumberdataContext numberdata) + { + return float.Parse(numberdata.GetText(), invariantNumberFormat); + } + else if (argContext.id() is IdContext id) + { + var name = id.GetText(); + return labelToFloat32(name, () => id.Start); + } + else + { + throw new InvalidDataException($"{FormatLineColumn(argContext.Start)} Unknown arg!"); + } + } + }; + } + + var resolveInt32ForIntTrigger = ResolveInt32Factory( + stringToInt32: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), + labelToInt32: LabelToInt32Converter + ); + + var resolveInt32ForSsub = ResolveInt32Factory( + stringToInt32: Helper.AllowedRangeFactory( + factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), + min: -2048, + max: 4095 + ), + labelToInt32: LabelToInt32Converter + ); + + var resolveInt32ForRelativeImm16 = ResolveInt32Factory( + stringToInt32: Helper.AllowedRangeFactory( + factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), + min: short.MinValue, + max: short.MaxValue + ), + labelToInt32: LabelToInt32Converter + ); + + var resolveInt32ForValueImm16 = ResolveInt32Factory( + stringToInt32: Helper.AllowedRangeFactory( + factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), + min: short.MinValue, + max: ushort.MaxValue + ), + labelToInt32: LabelToInt32Converter + ); + + var resolveInt32ForRelativeImm32 = ResolveInt32Factory( + stringToInt32: Helper.AllowedRangeFactory( + factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false), + min: int.MinValue, + max: int.MaxValue + ), + labelToInt32: LabelToInt32Converter + ); + + var resolveInt32ForValueImm32 = ResolveInt32Factory( + stringToInt32: Helper.AllowedRangeFactory( + factory: Helper.NumberdataContextToInt32ConverterFactory(allowFloat: true), + min: int.MinValue, + max: int.MaxValue + ), + labelToInt32: LabelToInt32Converter + ); + + var resolveFloat32ForValueFloat32 = ResolveFloat32Factory( + labelToFloat32: LabelToFloat32Converter + ); + + int lastBssBytes = 0; + + var compilePasses = new CompilePass[] { + new CompilePass(Index: 0, First: true, Last: false), // resolve code placement and labels offset + new CompilePass(Index: 1, First: false, Last: false), // resolve equ (const) + new CompilePass(Index: 2, First: false, Last: true), // compile + }; + + foreach (var pass in compilePasses) + { + var words = new MemoryStream(); + + void WordAlignment() + { + if ((words.Length & 1) != 0) + { + words.WriteByte(0); + } + } + + BinaryMapping.WriteObject(words, header); + + if (!pass.First) + { + if (header.WorkSize < lastBssBytes) + { + logger.Warn($"WorkSize {header.WorkSize} is extended to {lastBssBytes}"); + + words.Position = 16; + words.Write(BitConverter.GetBytes(lastBssBytes)); + words.Seek(0, SeekOrigin.End); + } + } + + foreach (var intTrigger in header.Triggers + .Select( + item => + { + return new IntTrigger + { + Key = item.Key, + Addr = resolveInt32ForIntTrigger(Helper.ParseAsArg(item.Addr), pass), + }; + } + ) + ) + { + BinaryMapping.WriteObject(words, intTrigger); + } + + BinaryMapping.WriteObject(words, new IntTrigger { Addr = 0, Key = 0, }); + + var codeSeg = new CodeSegment(words); + var bssSeg = new BssSegment(); + ISegment segment = codeSeg; + + void AddLabel(string labelName, ILabel labelValue, Func getTokenPos) + { + if (pass.First) + { + if (!labels.TryAdd(labelName, labelValue)) + { + throw new InvalidDataException($"{FormatLineColumn(getTokenPos().Start)} Redefine of label {labelName}"); + } + } + else + { + labels[labelName] = labelValue; + } + } + + void WalkStatements(ProgContext root) + { + foreach (var st in root.statement()) + { + //var pc = (int)(words.Length / 2 - 8); + + if (st.section() is SectionContext section) + { + var id = section.section_id(); + var sectionName = id.GetText(); + if (sectionName == ".text") + { + segment = codeSeg; + } + else if (sectionName == ".bss") + { + segment = bssSeg; + } + else + { + throw new InvalidDataException($"{FormatLineColumn(id.Start)} Unknown section name {sectionName}"); + } + continue; + } + else if (st.equ() is EquContext equ) + { + var intValue = Helper.NumberdataContextToInt32ConverterFactory(allowFloat: false).Invoke(equ.numberdata()); + + AddLabel( + equ.name.GetText(), + new ConstLabel { Value = intValue, }, + () => equ.name + ); + } + + if (st.label() is LabelContext label) + { + WordAlignment(); + var id = label.id(); + AddLabel( + id.GetText(), + segment.GetLabel(), + () => id + ); + } + + if (st.order() is OrderContext order) + { + if (order.db() is DbContext db) + { + foreach (var byteData in db.bytedata()) + { + if (byteData.numberdata() is NumberdataContext numberData) + { + segment.WriteByte(Helper.GetAsByte(numberData)); + } + else if (byteData.StringData() is ITerminalNode stringData) + { + var text = stringData.GetText(); + var bytes = Encoding.ASCII.GetBytes(text.Substring(1, text.Length - 2)); + segment.Write(bytes); + } + else if (byteData.id() is IdContext id) + { + var value = pass.First ? 0 : LabelToInt32Converter(id.GetText(), () => id.Start); + segment.WriteByte((byte)value); + } + else + { + throw new InvalidDataException($"{FormatLineColumn(byteData.Start)} Unknown byte data!"); + } + } + } + else if (order.resb() is ResbContext resb) + { + if (resb.numberdata() is NumberdataContext numberdata) + { + var numBytes = Helper.GetAsInt32(numberdata); + segment.AllocateBytes(numBytes); + } + else if (resb.id() is IdContext id) + { + var numBytes = LimitInt32Range( + pass.First + ? 0 + : LabelToInt32Converter(id.GetText(), () => id.Start), + min: int.MinValue, + max: int.MaxValue, + getStart: () => id.Start + ); + segment.AllocateBytes(numBytes); + } + } + else if (order.dw() is DwContext dw) + { + WordAlignment(); + foreach (var wordData in dw.worddata()) + { + if (wordData.numberdata() is NumberdataContext numberdata) + { + segment.Write(BitConverter.GetBytes(Helper.GetAsUInt16(numberdata))); + } + else if (wordData.id() is IdContext id) + { + var value = (ushort)LimitInt32Range(pass.First ? 0 : LabelToInt32Converter(id.GetText(), () => id.Start), min: -127, max: 255, () => id.Start); + segment.Write(BitConverter.GetBytes(value)); + } + else + { + throw new InvalidDataException($"{FormatLineColumn(wordData.Start)} Unknown word data!"); + } + } + } + else if (order.resw() is ReswContext resw) + { + if (resw.numberdata() is NumberdataContext numberdata) + { + var numBytes = 2 * Helper.GetAsInt32(numberdata); + segment.AllocateBytes(numBytes); + } + else if (resw.id() is IdContext id) + { + var numBytes = 2 * LimitInt32Range(pass.First ? 0 : LabelToInt32Converter(id.GetText(), () => id.Start), min: int.MinValue, max: int.MaxValue, () => id.Start); + segment.AllocateBytes(numBytes); + } + } + else if (order.instruction() is InstructionContext instr) + { + var name = instr.id().GetText(); + if (!instructionDict.TryGetValue(name, out var desc)) + { + throw new InvalidDataException($"{FormatLineColumn(instr.Start)} Unknown instruction '{name}'!"); + } + + if (segment is not CodeSegment thisSegment) + { + throw new InvalidDataException($"{FormatLineColumn(instr.Start)} This must be placed at `section .text`!"); + } + + var pc = thisSegment.PC; + + var word = new BdxInstruction(desc.Code); + + var args = desc.Args ?? new Arg[0]; + + var instrArgs = instr.arg(); + + for (int x = 0; x < args.Length; x++) + { + if (args[x].Type == ArgType.Ssub) + { + word.Ssub = (ushort)resolveInt32ForSsub(instrArgs[x], pass); + } + } + + segment.Write(BitConverter.GetBytes(word.Code)); + + for (int x = 0; x < args.Length; x++) + { + if (args[x].Type == ArgType.Imm16) + { + if (args[x].IsRelative) + { + var baseOffset = -pc - desc.CodeSize; + + segment.Write(BitConverter.GetBytes((ushort)(baseOffset + resolveInt32ForRelativeImm16(instrArgs[x], pass)))); + } + else + { + segment.Write(BitConverter.GetBytes((ushort)(resolveInt32ForValueImm16(instrArgs[x], pass)))); + } + } + else if (args[x].Type == ArgType.Imm32) + { + if (args[x].IsRelative) + { + var baseOffset = -pc - desc.CodeSize; + + segment.Write(BitConverter.GetBytes((uint)(baseOffset + resolveInt32ForRelativeImm32(instrArgs[x], pass)))); + } + else + { + segment.Write(BitConverter.GetBytes((uint)(resolveInt32ForValueImm32(instrArgs[x], pass)))); + } + } + else if (args[x].Type == ArgType.Float32) + { + { + segment.Write(BitConverter.GetBytes((float)(resolveFloat32ForValueFloat32(instrArgs[x], pass)))); + } + } + } + } + else if (order.include() is IncludeContext include) + { + var scriptName = include.FileName().GetText().Trim('"'); + var subScript = loadScript(scriptName); + + var stream = FromString(subScript, scriptName); + var lexer = new BdxScriptLexer(stream); + var tokens = new CommonTokenStream(lexer); + var parser = new BdxScriptParser(tokens); + var subRoot = parser.prog(); + + WalkStatements(subRoot); + } + else + { + //throw new InvalidDataException("Unknown statement!"); + // maybe NL + } + } + } + } + + { + var stream = FromString(script, scriptName); + var lexer = new BdxScriptLexer(stream); + var tokens = new CommonTokenStream(lexer); + var parser = new BdxScriptParser(tokens); + var root = parser.prog(); + + WalkStatements(root); + } + + WordAlignment(); + + lastBssBytes = bssSeg.numBytes; + + if (pass.Last) + { + Content = words.ToArray(); + } + } + } + + private int LimitInt32Range(int value, int min, int max, Func getStart) + { + if (min <= value && value <= max) + { + return value; + } + + throw new ArgumentOutOfRangeException(FormatErrorMessage(getStart(), $"Integer must be in range of from {min} to {max}")); + } + + private static ICharStream FromString(string script, string sourceName) + { + var stream = CharStreams.fromString(script); + if (stream is CodePointCharStream charStream) + { + charStream.name = sourceName; + } + return stream; + } + + private static string FormatLineColumn(IToken start) => $"{start.InputStream.SourceName} line {start.Line}:{start.Column}"; + + private static string FormatErrorMessage(IToken start, IFormattable text) => $"{start.InputStream.SourceName} line {start.Line}:{start.Column} {text}"; + private static string FormatErrorMessage(IToken start, string text) => $"{start.InputStream.SourceName} line {start.Line}:{start.Column} {text}"; + + private static class Helper + { + internal static int GetAsInt32(NumberdataContext numberData) + { + var decimalNumber = numberData.decimalnumber; + if (decimalNumber != null) + { + var body = decimalNumber.Text; + + if (uint.TryParse(body, out uint uintVal)) + { + return (int)uintVal; + } + else if (int.TryParse(body, out int intVal)) + { + return intVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); + } + } + else if (numberData.hexnumber is IToken hexNumber) + { + var body = hexNumber.Text; + + if (uint.TryParse(body, NumberStyles.HexNumber, null, out uint uintVal)) + { + return (int)uintVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); + } + } + else if (numberData.floatnumber is IToken) + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); + } + else + { + throw new InvalidDataException($"{FormatLineColumn(numberData.Start)} Unknown number data!"); + } + } + + internal static ArgContext ParseAsArg(string addr) + { + var stream = CharStreams.fromString(addr); + var lexer = new BdxScriptLexer(stream); + var tokens = new CommonTokenStream(lexer); + var parser = new BdxScriptParser(tokens); + + return parser.arg(); + } + + internal static Func NumberdataContextToInt32OrFloat32ConverterFactory() + { + return (NumberdataContext numberData) => + { + var decimalNumber = numberData.decimalnumber; + if (decimalNumber != null) + { + var body = decimalNumber.Text; + + if (uint.TryParse(body, out uint uintVal)) + { + return (int)uintVal; + } + else if (int.TryParse(body, out int intVal)) + { + return intVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); + } + } + else if (numberData.hexnumber is IToken hexNumber) + { + var body = hexNumber.Text; + + if (uint.TryParse(body, NumberStyles.HexNumber, null, out uint uintVal)) + { + return (int)uintVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int32 here")); + } + } + else if (numberData.floatnumber is IToken floatnumber) + { + var body = floatnumber.Text; + + if (float.TryParse(body, NumberStyles.HexNumber, invariantNumberFormat, out float floatVal)) + { + return (float)floatVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be float32 here")); + } + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Unknown number data!")); + } + }; + } + + internal static Func NumberdataContextToInt32ConverterFactory(bool allowFloat) + { + var func = NumberdataContextToInt32OrFloat32ConverterFactory(); + + return (NumberdataContext numberData) => + { + var value = func(numberData); + + if (value is int intValue) + { + return intValue; + } + else if (value is float floatValue) + { + if (!allowFloat) + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); + } + return BitConverter.ToInt32(BitConverter.GetBytes(floatValue)); + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Numeric converter bug")); + } + }; + } + + internal static Func AllowedRangeFactory(Func factory, int min, int max) + { + return (NumberdataContext numberData) => + { + var value = factory(numberData); + if (min <= value && value <= max) + { + return value; + } + + throw new ArgumentOutOfRangeException(FormatErrorMessage(numberData.Start, $"The value must be in range of from {min} to {max}!")); + }; + } + + internal static byte GetAsByte(NumberdataContext numberData) + { + var decimalNumber = numberData.decimalnumber; + if (decimalNumber != null) + { + var body = decimalNumber.Text; + + if (byte.TryParse(body, out byte byteVal)) + { + return byteVal; + } + else if (sbyte.TryParse(body, out sbyte sbyteVal)) + { + return (byte)sbyteVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be byte here")); + } + } + else if (numberData.hexnumber is IToken hexNumber) + { + var body = hexNumber.Text; + + if (byte.TryParse(body, NumberStyles.HexNumber, null, out byte byteVal)) + { + return byteVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be byte here")); + } + } + else if (numberData.floatnumber is IToken) + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Unknown number data!")); + } + } + + internal static ushort GetAsUInt16(NumberdataContext numberData) + { + var decimalNumber = numberData.decimalnumber; + if (decimalNumber != null) + { + var body = decimalNumber.Text; + + if (ushort.TryParse(body, out ushort ushortVal)) + { + return ushortVal; + } + else if (short.TryParse(body, out short shortVal)) + { + return (byte)shortVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int16 here")); + } + } + else if (numberData.hexnumber is IToken hexNumber) + { + var body = hexNumber.Text; + + if (ushort.TryParse(body, NumberStyles.HexNumber, null, out ushort ushortVal)) + { + return ushortVal; + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Must be int16 here")); + } + } + else if (numberData.floatnumber is IToken) + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Float number is not allowed here")); + } + else + { + throw new InvalidDataException(FormatErrorMessage(numberData.Start, "Unknown number data!")); + } + } + } + + private interface ISegment + { + void Write(byte[] bytes); + void WriteByte(byte value); + void AllocateBytes(int num); + ILabel GetLabel(); + } + + private class BssSegment : ISegment + { + public int numBytes = 0; + + public void AllocateBytes(int num) + { + numBytes += num; + } + + public ILabel GetLabel() + { + return new BssLabel { ByteOffset = numBytes }; + } + + public void Write(byte[] bytes) + { + throw new InvalidOperationException("`section .bss` cannot place static data. Use `resb 4` or `resw 2` or such."); + } + + public void WriteByte(byte value) + { + throw new InvalidOperationException("`section .bss` cannot place static data. Use `resb 4` or `resw 2` or such."); + } + } + + private class CodeSegment : ISegment + { + private readonly MemoryStream _words; + + public CodeSegment(MemoryStream words) + { + _words = words; + } + + public int PC => (int)(_words.Length / 2 - 8); + + public void AllocateBytes(int num) + { + _words.Write(new byte[num]); + } + + public ILabel GetLabel() + { + return new CodeLabel { PC = PC }; + } + + public void Write(byte[] buffer) + { + _words.Write(buffer); + } + + public void WriteByte(byte value) + { + _words.WriteByte(value); + } + } + + private interface ILabel + { + + } + + private class CodeLabel : ILabel + { + public int PC { get; set; } + } + + private class BssLabel : ILabel + { + public int ByteOffset { get; set; } + } + + private class ConstLabel : ILabel + { + public int Value { get; set; } + } + + private record CompilePass( + int Index, + bool First, + bool Last + ); + + private static readonly IFormatProvider invariantNumberFormat = CultureInfo.InvariantCulture.NumberFormat; + } +} diff --git a/OpenKh.Command.Bdxio/Utils/BdxTrigger.cs b/OpenKh.Kh2/Bdx/Utils/BdxTrigger.cs similarity index 95% rename from OpenKh.Command.Bdxio/Utils/BdxTrigger.cs rename to OpenKh.Kh2/Bdx/Utils/BdxTrigger.cs index fc8747bc6..de823f34b 100644 --- a/OpenKh.Command.Bdxio/Utils/BdxTrigger.cs +++ b/OpenKh.Kh2/Bdx/Utils/BdxTrigger.cs @@ -1,37 +1,37 @@ -namespace OpenKh.Command.Bdxio.Utils -{ - public record BdxTrigger(string Label, int Key) - { - public static BdxTrigger[] GetKnownItems() => new BdxTrigger[] - { - new BdxTrigger("OBJ_INIT", 0x0), - new BdxTrigger("OBJ_MAIN", 0x1), - new BdxTrigger("UNIT_INIT", 0x2), - new BdxTrigger("UNIT_MAIN", 0x3), - new BdxTrigger("UNIT_FINALIZER", 0x4), - new BdxTrigger("TEST", 0x5), - new BdxTrigger("OBJ_DAMAGE", 0x6), - new BdxTrigger("NEWGAME", 0x7), - new BdxTrigger("PROGRESS_CALLBACK", 0x8), - new BdxTrigger("GAMEOVER", 0x9), - new BdxTrigger("SIGNAL_CALLBACK", 0xA), - new BdxTrigger("REACTION_CALLBACK", 0xB), - new BdxTrigger("SECOND_SET_CALLBACK", 0xC), - new BdxTrigger("OBJ_FALL", 0xD), - new BdxTrigger("OBJ_LAND", 0xE), - new BdxTrigger("OBJ_ATTACK", 0xF), - new BdxTrigger("OBJ_ANMATR_EFFECT", 0x10), - new BdxTrigger("OBJ_ANMATR_CALLBACK", 0x11), - new BdxTrigger("OBJ_CHANGE_ACT", 0x12), - new BdxTrigger("OBJ_REFLECT", 0x13), - new BdxTrigger("MAGIC_START", 0x14), - new BdxTrigger("MAGIC_SHOT", 0x15), - new BdxTrigger("LIMIT_START", 0x16), - new BdxTrigger("LIMIT_CALL", 0x17), - new BdxTrigger("LIMIT_ANMATR_EFFECT", 0x18), - new BdxTrigger("LIMIT_ANMATR_CALLBACK", 0x19), - new BdxTrigger("LIMIT_ATTACK", 0x1A), - new BdxTrigger("OBJ_IK_ADJUST_CALLBACK", 0x1B), - }; - } -} +namespace OpenKh.Kh2.Bdx.Utils +{ + public record BdxTrigger(string Label, int Key) + { + public static BdxTrigger[] GetKnownItems() => new BdxTrigger[] + { + new BdxTrigger("OBJ_INIT", 0x0), + new BdxTrigger("OBJ_MAIN", 0x1), + new BdxTrigger("UNIT_INIT", 0x2), + new BdxTrigger("UNIT_MAIN", 0x3), + new BdxTrigger("UNIT_FINALIZER", 0x4), + new BdxTrigger("TEST", 0x5), + new BdxTrigger("OBJ_DAMAGE", 0x6), + new BdxTrigger("NEWGAME", 0x7), + new BdxTrigger("PROGRESS_CALLBACK", 0x8), + new BdxTrigger("GAMEOVER", 0x9), + new BdxTrigger("SIGNAL_CALLBACK", 0xA), + new BdxTrigger("REACTION_CALLBACK", 0xB), + new BdxTrigger("SECOND_SET_CALLBACK", 0xC), + new BdxTrigger("OBJ_FALL", 0xD), + new BdxTrigger("OBJ_LAND", 0xE), + new BdxTrigger("OBJ_ATTACK", 0xF), + new BdxTrigger("OBJ_ANMATR_EFFECT", 0x10), + new BdxTrigger("OBJ_ANMATR_CALLBACK", 0x11), + new BdxTrigger("OBJ_CHANGE_ACT", 0x12), + new BdxTrigger("OBJ_REFLECT", 0x13), + new BdxTrigger("MAGIC_START", 0x14), + new BdxTrigger("MAGIC_SHOT", 0x15), + new BdxTrigger("LIMIT_START", 0x16), + new BdxTrigger("LIMIT_CALL", 0x17), + new BdxTrigger("LIMIT_ANMATR_EFFECT", 0x18), + new BdxTrigger("LIMIT_ANMATR_CALLBACK", 0x19), + new BdxTrigger("LIMIT_ATTACK", 0x1A), + new BdxTrigger("OBJ_IK_ADJUST_CALLBACK", 0x1B), + }; + } +} diff --git a/OpenKh.Kh2/OpenKh.Kh2.csproj b/OpenKh.Kh2/OpenKh.Kh2.csproj index a7f14128d..1ef158e8a 100644 --- a/OpenKh.Kh2/OpenKh.Kh2.csproj +++ b/OpenKh.Kh2/OpenKh.Kh2.csproj @@ -1,11 +1,13 @@ - netstandard2.0;net8.0 + net8.0 latest - 25.02.10.025.02.10.025.02.10.0-local25.02.10.0-localOpenKH contributorsOpenKHCopyright (C) OpenKH https://github.com/OpenKH/OpenKh + 25.02.10.025.02.10.025.02.10.0-local25.02.10.0-localOpenKH contributorsOpenKHCopyright (C) OpenKH https://github.com/OpenKH/OpenKhenable + + diff --git a/OpenKh.Patcher/BarEntryExtractor/ProvideExtractorsService.cs b/OpenKh.Patcher/BarEntryExtractor/ProvideExtractorsService.cs index fd1456cf6..67d1c90fa 100644 --- a/OpenKh.Patcher/BarEntryExtractor/ProvideExtractorsService.cs +++ b/OpenKh.Patcher/BarEntryExtractor/ProvideExtractorsService.cs @@ -1,6 +1,6 @@ -using OpenKh.Command.Bdxio.Utils; using OpenKh.Common; using OpenKh.Kh2; +using OpenKh.Kh2.Bdx.Utils; using OpenKh.Kh2.Messages; using System; using System.Collections.Generic; diff --git a/OpenKh.Patcher/Kh2Ps2Patch/PatchCodec.cs b/OpenKh.Patcher/Kh2Ps2Patch/PatchCodec.cs index a0881d709..e8e282962 100644 --- a/OpenKh.Patcher/Kh2Ps2Patch/PatchCodec.cs +++ b/OpenKh.Patcher/Kh2Ps2Patch/PatchCodec.cs @@ -3,21 +3,31 @@ namespace OpenKh.Patcher.Kh2Ps2Patch { /// - /// Encryptor and decryptor codes are taken from https://github.com/GovanifY/KH2FM_Toolkit /// - /// KH2FM_Toolkit is programmed by GovanifY https://www.govanify.com https://www.twitter.com/GovanifY - /// KH2FM_Toolkit Copyright (c) 2015 Gauvain "GovanifY" Roussel-Tarbouriech /// public class PatchCodec { + /// Attributions: + /// + /// The original KH2PATCH format (Noted here as "Legacy") has been devised by Xeeynamo. + /// The new KH2PATCH format (Noted here as "New") is the original format, improved upon by CrazyCatz00. + /// + /// Signature for the legacy format is 0x5032484B, for the new format is 0x5132484B. + /// + /// The new format can be compatible with the legacy format as long as it adheres to these differences: + /// + /// - Legacy format cannot edit OVL.IDX, it also can't edit the ISO direct. + /// - Legacy format is unable to add non-existing files. + /// - Legacy format patches cannot be decrypted. + private static readonly byte[] _xTab = Convert.FromBase64String( "WAzdWfckf08=" ); - private static readonly byte[] _gTab = Convert.FromBase64String( + private static readonly byte[] _cTab = Convert.FromBase64String( "pBxrgTANI1tcOqfe2/RzWqDCcNEoSKpyYrWafHwg4MciIHLMJsa8gC14tZXbNyF0BhG1fe+JSNcBp27Qbu58zA==" ); - public byte[] ApplyXeeynamosMethod(ReadOnlySpan input) + public byte[] ApplyLegacyFormatMethod(ReadOnlySpan input) { var tab = _xTab; var length = input.Length; @@ -29,9 +39,9 @@ public byte[] ApplyXeeynamosMethod(ReadOnlySpan input) return output; } - public byte[] ApplyGovanifYsMethod(ReadOnlySpan input) + public byte[] ApplyNewFormatMethod(ReadOnlySpan input) { - var tab = _gTab; + var tab = _cTab; var length = input.Length; var output = new byte[length]; for (int index = 0; 0 < length; index++) diff --git a/OpenKh.Patcher/Kh2Ps2Patch/PatchIO.cs b/OpenKh.Patcher/Kh2Ps2Patch/PatchIO.cs index f15c5b093..0aa598b7a 100644 --- a/OpenKh.Patcher/Kh2Ps2Patch/PatchIO.cs +++ b/OpenKh.Patcher/Kh2Ps2Patch/PatchIO.cs @@ -8,12 +8,6 @@ namespace OpenKh.Patcher.Kh2Ps2Patch { - /// - /// The patch formats are taken from https://github.com/GovanifY/KH2FM_Toolkit - /// - /// KH2FM_Toolkit is programmed by GovanifY https://www.govanify.com https://www.twitter.com/GovanifY - /// KH2FM_Toolkit Copyright (c) 2015 Gauvain "GovanifY" Roussel-Tarbouriech - /// public class PatchIO { public bool VerifySignature(Memory memory) diff --git a/OpenKh.Patcher/Kh2Ps2Patch/PatchIOHelper.cs b/OpenKh.Patcher/Kh2Ps2Patch/PatchIOHelper.cs index 8af300b68..4093efcf4 100644 --- a/OpenKh.Patcher/Kh2Ps2Patch/PatchIOHelper.cs +++ b/OpenKh.Patcher/Kh2Ps2Patch/PatchIOHelper.cs @@ -16,7 +16,7 @@ public PatchHeader Read(Memory memory) } { - var decoded = _patchCodec.ApplyXeeynamosMethod(memory.Span); + var decoded = _patchCodec.ApplyLegacyFormatMethod(memory.Span); if (_patchIo.VerifySignature(decoded)) { return _patchIo.Read(decoded); @@ -24,7 +24,7 @@ public PatchHeader Read(Memory memory) } { - var decoded = _patchCodec.ApplyGovanifYsMethod(memory.Span); + var decoded = _patchCodec.ApplyNewFormatMethod(memory.Span); if (_patchIo.VerifySignature(decoded)) { return _patchIo.Read(decoded); diff --git a/OpenKh.Patcher/Metadata.cs b/OpenKh.Patcher/Metadata.cs index d084ae7dd..b4f910868 100644 --- a/OpenKh.Patcher/Metadata.cs +++ b/OpenKh.Patcher/Metadata.cs @@ -1,77 +1,101 @@ using OpenKh.Kh2; +using SharpYaml; +using SharpYaml.Serialization; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; namespace OpenKh.Patcher { - public class Metadata + [YamlSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = YamlIgnoreCondition.WhenWritingDefault)] + + public class Preference { - public class Dependency - { - public string Name { get; set; } - } + public string Title { get; set; } + public string Key { get; set; } + public string Type { get; set; } + public string Description { get; set; } + public string Category { get; set; } + public string[]? Options { get; set; } + public object Value { get; set; } + } + public class Condition + { + public string Key { get; set; } + public object Value { get; set; } + } + + public class Metadata + { public string Title { get; set; } public string OriginalAuthor { get; set; } public string Description { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Game { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public int Specifications { get; set; } - public List Dependencies { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool IsCollection { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public List CollectionGames { get; set; } + public List? Preferences { get; set; } + public string Game { get; set; } + public int Specifications { get; set; } + public List? Dependencies { get; set; } + public bool IsCollection { get; set; } + public List? CollectionGames { get; set; } public List Assets { get; set; } - private static readonly IDeserializer deserializer = - new DeserializerBuilder() - .IgnoreFields() - .IgnoreUnmatchedProperties() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - private static readonly ISerializer serializer = - new SerializerBuilder() - .IgnoreFields() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - + [YamlIgnore] + public bool IsValid = true; - public static Metadata Read(Stream stream) + public static Metadata? Read(object inputFormat) { + string? _fetchYamlRAW = null; + + if (inputFormat is StringReader) + _fetchYamlRAW = (inputFormat as StringReader).ReadToEnd(); + + else if (inputFormat is string) + _fetchYamlRAW = File.ReadAllText(inputFormat as string); + + else + return null; + + // Replace all back slashes as Windows supports forward slashes but Linux doesn't support back slashes. + _fetchYamlRAW = _fetchYamlRAW.Replace('\\', '/'); + try { - return deserializer.Deserialize(new StreamReader(stream)); //Simplifed way of doing this. Cuts out the "deserializer" redundancies and variable for StreamReader(stream)) + var _fetchSerial = YamlSerializer.Deserialize(_fetchYamlRAW, new YamlSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + + // A single mod should not be able to patch a file more than once. + // Ignore any and all duplicates that target the same file. + var _fetchAssetUnique = _fetchSerial.Assets.DistinctBy(x => new { x.Name, x.Platform, x.Condition }); + _fetchSerial.Assets = _fetchAssetUnique.ToList(); + + return _fetchSerial; } - catch (YamlDotNet.Core.YamlException ex) + catch (YamlException ex) { // Handle YAML parsing errors Debug.WriteLine($"Error deserializing YAML: {ex.Message}"); - string originalTitle = string.Empty; + var _fetchTitle = string.Empty; + var _fetchMatch = Regex.Match(_fetchYamlRAW, @"(?<=title:).*", RegexOptions.None, TimeSpan.FromMilliseconds(500)); - // Extract title using regex - stream.Position = 0; // Reset stream position - using (var reader = new StreamReader(stream)) - { - string yamlContent = reader.ReadToEnd(); - var match = Regex.Match(yamlContent, @"(?<=title:).*"); - if (match.Success) - { - originalTitle = match.Value.Trim(); - } - } + if (_fetchMatch.Success) + _fetchTitle = _fetchMatch.Value.Trim(); var metadata = new Metadata { - Title = $"{originalTitle}* \nMOD YML ERROR DETECTED: CHECK FORMATTING" + Title = _fetchTitle, + IsValid = false }; return metadata; // Return modified metadata indicating failure } + catch (Exception ex) { // Handle other unexpected errors @@ -83,17 +107,15 @@ public static Metadata Read(Stream stream) public void Write(Stream stream) { using (var writer = new StreamWriter(stream)) - { - serializer.Serialize(writer, this); - } + YamlSerializer.Serialize(writer, this, new YamlSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, DefaultIgnoreCondition = YamlIgnoreCondition.WhenWritingDefault }); } public override string ToString() => - serializer.Serialize(this); + YamlSerializer.Serialize(this, new YamlSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, DefaultIgnoreCondition = YamlIgnoreCondition.WhenWritingDefault }); } public class AssetFile { - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Name { get; set; } + public string Name { get; set; } /// /// "areadatascript" @@ -108,7 +130,7 @@ public class AssetFile /// "spawnpoint" /// "synthpatch" /// - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Method { get; set; } + public string Method { get; set; } /// /// null @@ -117,7 +139,7 @@ public class AssetFile /// "pc" /// "ps2" /// - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Platform { get; set; } + public string Platform { get; set; } /// /// (null) @@ -143,11 +165,12 @@ public class AssetFile /// Recom /// Theater /// - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Package { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public List Multi { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public List Source { get; set; } + public string Package { get; set; } + public Condition Condition { get; set; } + public List Multi { get; set; } + public List Source { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool Required { get; set; } + public bool Required { get; set; } /// /// "areadatascript" @@ -184,13 +207,13 @@ public class AssetFile /// "trsr" /// "vtbl" /// - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Type { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public Bar.MotionsetType MotionsetType { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Language { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool IsSwizzled { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public int Index { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public string Game { get; set; } - [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool CollectionOptional { get; set; } + public string Type { get; set; } + public Bar.MotionsetType MotionsetType { get; set; } + public string Language { get; set; } + public bool IsSwizzled { get; set; } + public int Index { get; set; } + public string Game { get; set; } + public bool CollectionOptional { get; set; } } public class Multi diff --git a/OpenKh.Patcher/OpenKh.Patcher.csproj b/OpenKh.Patcher/OpenKh.Patcher.csproj index 0c265a56b..443c5966b 100644 --- a/OpenKh.Patcher/OpenKh.Patcher.csproj +++ b/OpenKh.Patcher/OpenKh.Patcher.csproj @@ -5,12 +5,12 @@ 25.02.10.025.02.10.025.02.10.0-local25.02.10.0-localOpenKH contributorsOpenKHCopyright (C) OpenKH https://github.com/OpenKH/OpenKh + - diff --git a/OpenKh.Patcher/PatcherProcessor.cs b/OpenKh.Patcher/PatcherProcessor.cs index 60b80305b..2a294a2fe 100644 --- a/OpenKh.Patcher/PatcherProcessor.cs +++ b/OpenKh.Patcher/PatcherProcessor.cs @@ -1,16 +1,33 @@ using OpenKh.Bbs; -using OpenKh.Command.Bdxio.Models; -using OpenKh.Command.Bdxio.Utils; + using OpenKh.Common; +using OpenKh.Common.Archives; +using OpenKh.Egs; using OpenKh.Imaging; +using OpenKh.Kh1; using OpenKh.Kh2; +using OpenKh.Kh2.Bdx.Models; +using OpenKh.Kh2.Bdx.Utils; using OpenKh.Kh2.Messages; using System; +using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Net.Security; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Xml.Linq; +using Xe.IO; using YamlDotNet.Serialization; +using static OpenKh.Kh2.Dpd; +using static OpenKh.Patcher.PatcherProcessor; +using static System.Net.Mime.MediaTypeNames; namespace OpenKh.Patcher { @@ -66,297 +83,370 @@ public void CopyOriginalFile(string fileName, string dstFile) public void Patch(string originalAssets, string outputDir, string modFilePath) { - var metadata = File.OpenRead(modFilePath).Using(Metadata.Read); + var metadata = Metadata.Read(modFilePath); var modBasePath = Path.GetDirectoryName(modFilePath); Patch(originalAssets, outputDir, metadata, modBasePath); } - List GamesList = new List() + public static Dictionary GameShorthand = new Dictionary() { - "kh2", - "kh1", - "bbs", - "Recom", + { 0, "kh1" }, + { 1, "kh2" }, + { 2, "Recom" }, + { 3, "bbs" }, + { 4, "kh3d" } }; - /// (GameEdition) 0=OpenKH, 1=PCSX2-EX, 2=PC - /// If true, always the first package file (kh1_first, bbs_first, kh2_first or such) is selected. - /// If true, always invoke context.CopyOriginalFile - /// (GameId) "kh1", "kh2", "bbs", "Recom", "kh3d" - /// en, jp - public void Patch( - string originalAssets, - string outputDir, - Metadata metadata, - string modBasePath, - int platform = 1, - bool fastMode = false, + public async Task Patch( + string extractDataPath, + string buildOutputPath, + Metadata modMetadata, + string modFilesPath, + string gameFilesPath = null, + int targetPlatform = 0x00, + int targetGame = 0x01, + bool isJapanese = false, + CancellationToken? cancelToken = null, IDictionary packageMap = null, - string LaunchGame = null, - string Language = "en", - bool Tests = false, - Dictionary collectionOptionalEnabledMods = null - ) + Dictionary collectionOptionalEnabledMods = null, + Func reportProgress = null, + bool Tests = false) { - if (collectionOptionalEnabledMods == null) - collectionOptionalEnabledMods = new Dictionary { }; - var context = new Context(metadata, originalAssets, modBasePath, outputDir); + var _isExtraction = extractDataPath != null; + var _fetchGameId = GameShorthand[targetGame]; + + var _protectPackageMap = new object(); + + var _fetchCollectionMods = new Dictionary { }; + var _fetchFileDictionary = new ConcurrentDictionary(); + + if (collectionOptionalEnabledMods != null) + _fetchCollectionMods = collectionOptionalEnabledMods; + try { + // A lot of this class relies on this existing. I am in no mood to rewrite that much code yet. + var _fetchContext = new Context(modMetadata, extractDataPath, modFilesPath, buildOutputPath); - if (metadata.Assets == null) - throw new Exception("No assets found."); - if (metadata.Game != null && GamesList.Contains(metadata.Game.ToLower()) && metadata.Game.ToLower() != LaunchGame.ToLower()) + // If the mod has a game declared and it doesn't match the current game, don't build it. + if (modMetadata.Game != null && modMetadata.Game.ToLower() != _fetchGameId) return; - if (metadata.IsCollection && !metadata.CollectionGames.Contains(LaunchGame)) + + // If the mod is part of a collection and the collection doesn't support the current game, don't build it. + if (modMetadata.IsCollection && !modMetadata.CollectionGames.Contains(_fetchGameId)) return; - var exclusiveLock = new object(); - metadata.Assets.AsParallel().ForAll(assetFile => + // If the mod does not have any assets, throw an error. This should not happen. + if (modMetadata.Assets == null) + throw new NullReferenceException("The mod doesn't contain any assets."); + + var _assetProcessCount = 0; + var _assetTotalCount = modMetadata.Assets.Count; + + // If the build is not extraction-based: + if (!_isExtraction && targetPlatform != 0x00) + { + // Fetch a list of all header files for the targeted game. + var _fetchDataPath = Path.Combine(gameFilesPath, "Image", targetPlatform == 0x01 ? "dt" : (isJapanese ? "jp" : "en")); + var _fetchHeaderFiles = Directory.GetFiles(_fetchDataPath).Where(x => x.Contains(_fetchGameId) && x.EndsWith(".hed")); + + // Start a parallel for every header file. + await Parallel.ForEachAsync(_fetchHeaderFiles.AsParallel(), new ParallelOptions() { CancellationToken = cancelToken ?? new CancellationToken() }, async (_fetchHeader, _fetchCancelToken) => + { + // Load up the header file and read it as a HED class. + using (var _fetchHeaderStream = File.OpenRead(_fetchHeader)) + { + var _fetchPackageName = Path.GetFileNameWithoutExtension(_fetchHeader); + var _fetchHeaderChildren = Hed.Read(_fetchHeaderStream); + + // Record every hash with its corresponding package name for speedier handling. + // This eliminates the need to inquire every package for every single file. + foreach (var _fetchEntry in _fetchHeaderChildren) + { + _fetchFileDictionary.TryAdd(Convert.ToHexString(_fetchEntry.MD5), _fetchPackageName); + + if (_fetchCancelToken.IsCancellationRequested) + break; + } + } + }); + } + + // Start a parallel for all the assets: + await Parallel.ForEachAsync(modMetadata.Assets.AsParallel(), new ParallelOptions() { CancellationToken = cancelToken ?? new CancellationToken() }, async (_fetchAsset, _fetchCancelToken) => { - if (assetFile.Game != null && assetFile.Game != LaunchGame) + // Process callback for progress. + _assetProcessCount++; + + // If the asset has a game declared and it doesn't match the current game, skip it. + if (_fetchAsset.Game != null && _fetchAsset.Game != _fetchGameId) return; - if (assetFile.CollectionOptional == true) - if (!collectionOptionalEnabledMods.ContainsKey(assetFile.Name)) - return; - else if (!collectionOptionalEnabledMods[assetFile.Name]) + + // I don't know what this does but it is here for compat. + if (_fetchAsset.CollectionOptional == true && (!_fetchCollectionMods.ContainsKey(_fetchAsset.Name) || !_fetchCollectionMods[_fetchAsset.Name])) + return; + + if (_fetchAsset.Condition != null) + { + var _fetchConditionKey = _fetchAsset.Condition.Key; + var _fetchConditionValue = _fetchAsset.Condition.Value; + + var _fetchConditionMain = modMetadata.Preferences.FirstOrDefault(x => x.Key == _fetchConditionKey); + + if (_fetchConditionMain != null && !Object.Equals(_fetchConditionValue, _fetchConditionMain.Value)) return; - var names = new List(); - names.Add(assetFile.Name); - if (assetFile.Multi != null) - names.AddRange(assetFile.Multi.Select(x => x.Name).Where(x => !string.IsNullOrEmpty(x))); + } - foreach (var name in names) + // Fetch all the target names to be used. + var _fetchFileNames = new List(); + var _fetchMultiNames = _fetchAsset.Multi != null ? _fetchAsset.Multi.Select(x => x.Name) + .Where(x => !string.IsNullOrEmpty(x)) : null; + + _fetchFileNames.Add(_fetchAsset.Name); + + if (_fetchMultiNames != null) + _fetchFileNames.AddRange(_fetchMultiNames); + + // If the platform for the asset isn't declared, default it to be both. + _fetchAsset.Platform = _fetchAsset.Platform != null ? _fetchAsset.Platform.ToLower() : "both"; + + foreach (var _fetchName in _fetchFileNames) { - if (assetFile.Platform == null) - assetFile.Platform = "both"; + // Check discrepancy for JP-specific files. + var _doesRegionMatch = (!isJapanese && !_fetchName.Contains(".a.jp") && !_fetchName.Contains("/jp/")) || (isJapanese && (_fetchName.Contains(".a.jp") || _fetchName.Contains("/jp/"))); + var _isAssetExclusivePS2 = _fetchName.Contains(".a.fm") || _fetchName.Contains("/fm/"); - if (assetFile.Required && !File.Exists(context.GetOriginalAssetPath(name))) - continue; + // Declare whether the asset is patchable or not. + var _isAssetPatchable = _fetchAsset.Method != "copy" && _fetchAsset.Method != "imd"; - string _packageFile = null; - switch (LaunchGame) - { - case "kh1": - _packageFile = assetFile.Package != null && !fastMode ? assetFile.Package : "kh1_first"; - break; - case "bbs": - _packageFile = assetFile.Package != null && !fastMode ? assetFile.Package : "bbs_first"; - break; - case "Recom": - if (assetFile != null) - _packageFile = "Recom"; - break; - default: - _packageFile = assetFile.Package != null && !fastMode ? assetFile.Package : "kh2_first"; - break; - } + // This is used for package map purposes. + var _fetchPackageMap = ""; - if (Path.IsPathRooted(name) && !Path.GetPathRoot(name).Equals(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) - { - Log.Err($"File Path \"" + name + "\" cannot be copied as it is rooted and can cause instability! Aborting..."); - throw new PatcherException(metadata, new InvalidOperationException("Root Copy Detected!")); - } + // Construct the many paths that will be needed for the asset. - var dstFile = context.GetDestinationPath(name); - var packageMapLocation = ""; - var _pcFile = name.Contains("remastered") || name.Contains("raw"); + /* + * -> _fetchOriginalPath = Path to the target file from the game data. Constructed and used only if extraction exists. + * -> _fetchVariablePath = Path to the target file as it exists in the build folder. Only used if the file is patchable. [Type isn't COPY or IMD] + * -> _fetchExternalPath = Path to the source file as it exists in the mod's source folder. Used if the file is neither patchable nor internal. + * -> _fetchInternalPath = Path to the source file from the game data. Used if the file is not patchable but is internal. Constructed and used only if extraction exists. + */ - // Special case for mods that want to bundle scripts or DLL files - var nonGameFile = name.StartsWith("scripts/") || name.StartsWith("scripts\\") || name.StartsWith("dlls/") || name.StartsWith("dlls\\"); + var _fetchOriginalPath = _isExtraction ? Path.Combine(extractDataPath, _fetchName) : null; + var _fetchVariablePath = _isAssetPatchable && _fetchAsset.Source[0].Type != "internal" ? Path.Combine(buildOutputPath, _fetchName) : null; + var _fetchExternalPath = !_isAssetPatchable && (_fetchAsset.Source[0].Type != "internal" && _fetchAsset.Source[0].Name != null) ? Path.Combine(modFilesPath, _fetchAsset.Source[0].Name) : null; + var _fetchInternalPath = !_isAssetPatchable && (_fetchAsset.Source[0].Type == "internal" && _fetchAsset.Source[0].Name != null && _isExtraction) ? Path.Combine(extractDataPath, _fetchAsset.Source[0].Name) : null; - var _extraPath = _pcFile ? "" : "original/"; + // Fetch the parent directory of the file. + var _fetchFileParent = _fetchName.Split([Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]).FirstOrDefault(); + + // Construct the target path and directory for the file. + + var _fetchTargetPath = Path.Combine(buildOutputPath, _fetchName); + var _fetchTargetDir = Path.GetDirectoryName(_fetchTargetPath); + + // If declared, fetch the package name for the asset. + // This is used in hard-patching and for package mapping. + var _fetchPackage = _fetchAsset.Package != null ? _fetchAsset.Package : $"{_fetchGameId}_first"; + + // If the asset is declared REQUIRED, the game is extracted, yet the original file doesn't exist: Skip it. + if (_fetchAsset.Required && !_isExtraction && !File.Exists(_fetchOriginalPath)) + continue; + + // Fetch certain information about the file. + + var _isFileRAW = _fetchFileParent == "raw"; + var _isFileRemastered = _fetchFileParent == "remastered"; + var _isFileSpecial = _fetchFileParent == "scripts" || _fetchFileParent == "dll"; + + var _isFilePC = _isFileRemastered || _isFileRAW; + + // If the file is special, commit it to the package map as such. + if (_isFileSpecial) + _fetchPackageMap = "special/" + _fetchName; - if (nonGameFile) - { - packageMapLocation = "special/" + name; - } else { - switch (platform) - { - default: - { - if (assetFile.Platform.ToLower() == "pc") - continue; - - else if (_pcFile) - continue; - } - break; + // If the target platform is the PS2 and the file is PC-specific, skip it. + if (targetPlatform == 0x00 && _isFilePC && (_fetchFileParent == "dll" || _fetchAsset.Platform == "pc")) + continue; - case 2: - { - if (assetFile.Platform.ToLower() == "ps2") - continue; + // If the target platform is not PS2: + else if (targetPlatform != 0x00) + { + // But the asset is, skip it. + if (_fetchAsset.Platform == "ps2" || _isAssetExclusivePS2) + continue; - if (assetFile.Platform.ToLower() != "ps2") - packageMapLocation = _packageFile + "/" + _extraPath + name; + if (!_doesRegionMatch && (_isAssetPatchable || _fetchAsset.Source[0].Type == "internal")) + continue; - else if (_pcFile) - packageMapLocation = _packageFile + "/" + name; - } - break; + // Otherwise, commit it to the package map. + _fetchPackageMap = Path.Combine(_fetchPackage, _isFilePC ? "" : "original/", _fetchName); } } - if (packageMap != null && packageMapLocation.Length > 0) + // Lock the package map and commit the constructed string. + if (packageMap != null && _fetchPackageMap.Length > 0) { - // Protect against multiple mods having the same file where one uses forward slash and one uses backslash - lock (exclusiveLock) - { - packageMap[name.Replace("\\", "/")] = packageMapLocation; - } + lock (_protectPackageMap) + packageMap[_fetchName.Replace("\\", "/")] = _fetchPackageMap; } - context.EnsureDirectoryExists(dstFile); + // If the target directory does not exist, create it. + if (!Directory.Exists(_fetchTargetDir)) + Directory.CreateDirectory(_fetchTargetDir); - //Update: Prevent from copying a blank file should it not exist. - try + // If a built version of the file already exists, patch that one. + if (_fetchVariablePath != null && File.Exists(_fetchVariablePath)) { - bool multi = false; - if (assetFile.Multi != null) + using (var _fileStream = File.Open(_fetchVariablePath, FileMode.OpenOrCreate)) + PatchFile(_fetchContext, _fetchAsset, _fileStream); + } + + // Otherwise; + else + { + byte[] _fetchAssetData = null; + + // If the asset is not patchable, meaning it has to be copied from somewhere: + if (!_isAssetPatchable) { - foreach (var entry in assetFile.Multi) - { - if (File.Exists(context.GetOriginalAssetPath(entry.Name))) - { - multi = true; - } - } + // If the file type is internal, the internal path is valid, and the file exists: Copy it to target. + if (_fetchAsset.Source[0].Type == "internal" && _fetchInternalPath != null && File.Exists(_fetchInternalPath)) + File.Copy(_fetchInternalPath, _fetchTargetPath, true); + + // If the file type is NOT internal, the external path is valid, and the file exists: Copy it to target. + else if (_fetchExternalPath != null && File.Exists(_fetchExternalPath)) + File.Copy(_fetchExternalPath, _fetchTargetPath, true); } - //If editing subfiles (not Method: copy and not Method: imd) make sure the original file exists OR - //If copying a file from the mod (NOT Type: internal) make sure it exists (doesnt check if the location its going normally exists) OR - //If copying a file from the users extraction (Type: internal) make sure it exists (doesnt check if the location its going normally exists) OR - //Ignore if its from a test - - var needToCopyOriginalFile = - (false - || (true - && assetFile.Method != "copy" - && assetFile.Method != "imd" - && (false - || File.Exists(context.GetOriginalAssetPath(assetFile.Name)) - || multi - ) - ) - || (true - && (assetFile.Method == "copy" || assetFile.Method == "imd") - && assetFile.Source[0].Type != "internal" - && File.Exists(context.GetSourceModAssetPath(assetFile.Source[0].Name)) - ) - || (true - && (assetFile.Method == "copy" || assetFile.Method == "imd") - && assetFile.Source[0].Type == "internal" - && (false - || File.Exists(context.GetOriginalAssetPath(assetFile.Source[0].Name)) - || multi - ) - ) - || Tests - ); - if (needToCopyOriginalFile) + // If the asset is patchable, the original path is valid, and the file exists: Copy it to target. + else if (_isAssetPatchable && _fetchOriginalPath != null && File.Exists(_fetchOriginalPath)) + File.Copy(_fetchOriginalPath, _fetchTargetPath, true); + + // If after the above the target file STILL does not exists, try to fetch it from the game data. + if (!File.Exists(_fetchTargetPath)) { - context.CopyOriginalFile(name, dstFile); + if (targetPlatform != 0x00) + { + var _fetchTarget = _isAssetPatchable ? _fetchName : _fetchAsset.Source[0].Name; - using var _stream = File.Open(dstFile, FileMode.OpenOrCreate, FileAccess.ReadWrite); - PatchFile(context, assetFile, _stream); + var _fetchParent = ""; + var _fetchChild = ""; - _stream.Close(); - _stream.Dispose(); - } - else - { - // The following codes are for validation purposes only. + if (_isFileRAW) + _fetchTarget = _fetchTarget.Replace("raw/", ""); - List globalFilePaths = new List { ".a.fr", ".a.gr", ".a.it", ".a.sp", ".a.us", "/fr/", "/gr/", "/it/", "/sp/", "/us/" }; - List emulatorRegionPaths = new List { "/jp/", "/us/", "/it/", "/sp/", "/gr/", "/fr/", "/fm/" }; - if (assetFile.Method != "copy" && assetFile.Method != "imd") - { - if (platform == 2) + if (_isFileRemastered) { - if (Language != "jp") - { - if (!context.GetOriginalAssetPath(name).Contains(".a.fm") && !context.GetOriginalAssetPath(name).Contains("/jp/")) - { - Log.Warn("File not found: " + context.GetOriginalAssetPath(name) + " Skipping. \nPlease check your game extraction."); - } - } - else - { - if (!globalFilePaths.Any(x => context.GetOriginalAssetPath(name).Contains(x))) - { - Log.Warn("File not found: " + context.GetOriginalAssetPath(name) + " Skipping. \nPlease check your game extraction."); - } - } + var _fetchMatch = Regex.Match(_fetchTarget, "[\\w,-]+\\.[a-zA-Z0-9]{2,4}", RegexOptions.None, TimeSpan.FromMilliseconds(500)); + + var _fetchIndex = _fetchTarget.IndexOf(_fetchMatch.Value); + var _fetchEndPoint = _fetchIndex + _fetchMatch.Value.Length; + + var _fetchSubFirst = _fetchTarget.Substring(0, _fetchEndPoint); + var _fetchSubSecond = _fetchTarget.Substring(_fetchEndPoint, _fetchTarget.Length - _fetchEndPoint); + + _fetchParent = _fetchSubFirst.Replace("remastered/", ""); + _fetchChild = _fetchSubSecond.Trim('/'); } - else + + var _fetchNameHash = Egs.Helpers.CreateMD5(_isFileRemastered ? _fetchParent : _fetchTarget); + var _fetchKeyExists = _fetchFileDictionary.ContainsKey(_fetchNameHash); + + if (_fetchKeyExists) { - string matchedRegion = emulatorRegionPaths.FirstOrDefault(x => name.Contains(x)); - if (matchedRegion != null) + var _fetchFilePack = _fetchFileDictionary[_fetchNameHash]; + + if (!String.IsNullOrEmpty(_fetchFilePack)) { - string emuRegionPath = context.GetOriginalAssetPath(name.Substring(0, name.IndexOf(matchedRegion) + 3)); - if (Directory.Exists(emuRegionPath)) + var _fetchDataPath = Path.Combine(gameFilesPath, "Image", targetPlatform == 0x01 ? "dt" : (isJapanese ? "jp" : "en")); + + var _fetchHeaderName = Path.Combine(_fetchDataPath, _fetchFilePack + ".hed"); + var _fetchPackageName = Path.Combine(_fetchDataPath, _fetchFilePack + ".pkg"); + + using (var _fetchHeaderStream = File.OpenRead(_fetchHeaderName)) { - Log.Warn("File not found: " + context.GetOriginalAssetPath(name) + " Skipping. \nPlease check your game extraction."); + var _fetchEntries = Hed.Read(_fetchHeaderStream); + var _fetchTargetEntry = _fetchEntries.FirstOrDefault(x => Convert.ToHexString(x.MD5) == _fetchNameHash); + + using (var _fetchPackageStream = File.OpenRead(_fetchPackageName)) + { + var _fetchTargetAsset = new EgsHdAsset(_fetchPackageStream.SetPosition(_fetchTargetEntry.Offset)); + + if (_isFileRemastered) + _fetchTargetAsset.RemasteredAssetsDecompressedData.TryGetValue(_fetchChild, out _fetchAssetData); + + else + _fetchAssetData = _isFileRAW ? _fetchTargetAsset.OriginalRawData : _fetchTargetAsset.OriginalData; + + if (_fetchAssetData != null) + await File.WriteAllBytesAsync(_fetchTargetPath, _fetchAssetData, CancellationToken.None); + } } } } } - else if (assetFile.Source[0].Type == "internal") + + else { - if (platform == 2) - { - if (Language != "jp") - { - if (!context.GetOriginalAssetPath(assetFile.Source[0].Name).Contains(".a.fm") && !context.GetOriginalAssetPath(assetFile.Source[0].Name).Contains("/jp/") && (assetFile.Multi == null || assetFile.Name == name)) - { - Log.Warn("File not found: " + context.GetOriginalAssetPath(assetFile.Source[0].Name) + " Skipping. \nPlease check your game extraction."); - } - } - else - { - if (!globalFilePaths.Any(x => context.GetOriginalAssetPath(assetFile.Source[0].Name).Contains(x)) && (assetFile.Multi == null || assetFile.Name == name)) - { - Log.Warn("File not found: " + context.GetOriginalAssetPath(assetFile.Source[0].Name) + " Skipping. \nPlease check your game extraction."); - } - } - } - else + var _fetchTarget = _isAssetPatchable ? _fetchName : _fetchAsset.Source[0].Name; + + using (var _fetchStreamISO = new FileStream(gameFilesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { - string matchedRegion = emulatorRegionPaths.FirstOrDefault(x => assetFile.Source[0].Name.Contains(x)); - if (matchedRegion != null) + switch (targetGame) { - string emuRegionPath = context.GetOriginalAssetPath(assetFile.Source[0].Name.Substring(0, assetFile.Source[0].Name.IndexOf(matchedRegion) + 3)); - if (Directory.Exists(emuRegionPath)) + case 0x00: + break; + case 0x01: { - Log.Warn("File not found: " + context.GetOriginalAssetPath(assetFile.Source[0].Name) + " Skipping. \nPlease check your game extraction."); + var _fetchOffsetIDX = IsoUtility.GetFileOffset(_fetchStreamISO, "KH2.IDX;1"); + var _fetchOffsetIMG = IsoUtility.GetFileOffset(_fetchStreamISO, "KH2.IMG;1"); + + var _fetchSubStrIDX = new SubStream(_fetchStreamISO, _fetchOffsetIDX * 0x800, _fetchStreamISO.Length - (_fetchOffsetIDX * 0x800)); + var _fetchSubStrIMG = new SubStream(_fetchStreamISO, _fetchOffsetIMG * 0x800, _fetchStreamISO.Length - (_fetchOffsetIMG * 0x800)); + + var _fetchIDX = Idx.Read(_fetchSubStrIDX); + var _fetchIMG = new Img(_fetchSubStrIMG, _fetchIDX, true); + + var _fetchEntry = _fetchIMG.Entries.FirstOrDefault(x => IdxName.Lookup(x) == _fetchTarget); + + if (_fetchEntry != null) + { + using (var _fetchStreamTarget = _fetchIMG.FileOpen(_fetchEntry)) + File.Create(_fetchTargetPath).Using(_tempStr => _fetchStreamTarget.CopyTo(_tempStr)); + } + + else + Debug.WriteLine("Entry not found: " + _fetchTarget); } + break; } } } - else - { - Log.Warn("File not found: " + context.GetSourceModAssetPath(assetFile.Source[0].Name) + " Skipping. \nPlease check your mod install of: " + metadata.Title); - } } + + // After all that, if the target file actually exists now: Patch it. + if (File.Exists(_fetchTargetPath)) + using (var _fileStream = File.Open(_fetchTargetPath, FileMode.OpenOrCreate)) + PatchFile(_fetchContext, _fetchAsset, _fileStream, _fetchAssetData); } - catch (IOException) { } - //This is here so the user does not have to close Mod Manager to see what the warnings were if any. Helpful especially on PC since the build window closes after build unlike emulator where it stays open during mod injection. - Log.Flush(); } + + if (reportProgress != null) + reportProgress(_assetProcessCount, _assetTotalCount); }); } + catch (TaskCanceledException) { } + catch (Exception ex) { - Log.Err($"Patcher failed: {ex.Message}"); - throw new PatcherException(metadata, ex); + throw new PatcherException(modMetadata, ex); } } - private static void PatchFile(Context context, AssetFile assetFile, Stream stream) + private static void PatchFile(Context context, AssetFile assetFile, Stream stream, byte[] originalData = null) { if (assetFile == null) throw new Exception("Asset file is null."); @@ -364,7 +454,7 @@ private static void PatchFile(Context context, AssetFile assetFile, Stream strea switch (assetFile.Method) { case "copy": - CopyFile(context, assetFile, stream); + CopyFile(context, assetFile, stream, originalData); break; case "bar": case "binarc": @@ -414,31 +504,42 @@ private static void PatchFile(Context context, AssetFile assetFile, Stream strea stream.SetLength(stream.Position); } - - - private static void CopyFile(Context context, AssetFile assetFile, Stream stream) + private static void CopyFile(Context context, AssetFile assetFile, Stream stream, byte[] originalData = null) { if (assetFile.Source == null || assetFile.Source.Count == 0) throw new Exception($"File '{assetFile.Name}' does not contain any source"); - string srcFile; - if (assetFile.Source[0].Type == "internal") { - srcFile = context.GetOriginalAssetPath(assetFile.Source[0].Name); + if (context.OriginalAssetPath != null) + { + var _fetchSource = Path.Combine(context.OriginalAssetPath, assetFile.Source[0].Name); + + using (var _fetchStream = File.OpenRead(_fetchSource)) + _fetchStream.CopyTo(stream); + } + + else if (originalData != null) + { + using (var _memoryRead = new MemoryStream(originalData)) + _memoryRead.CopyTo(stream); + } } + else { - srcFile = context.GetSourceModAssetPath(assetFile.Source[0].Name); - if (!File.Exists(srcFile)) - throw new FileNotFoundException($"The mod does not contain the file {assetFile.Source[0].Name}", srcFile); - } - using var srcStream = File.OpenRead(srcFile); - srcStream.CopyTo(stream); - } - + var _fetchSource = Path.Combine(context.SourceModAssetPath, assetFile.Source[0].Name); + if (!File.Exists(_fetchSource)) + Console.WriteLine($"The mod does not contain the file {assetFile.Source[0].Name} in {context.SourceModAssetPath}"); + else + { + using (var _fetchStream = File.OpenRead(_fetchSource)) + _fetchStream.CopyTo(stream); + } + } + } //Binarc Update: Specify by Name OR Index. Some files in BARS may have the same name but different indexes, and you want to patch a later index only. private static void PatchBinarc(Context context, AssetFile assetFile, Stream stream) @@ -451,6 +552,17 @@ private static void PatchBinarc(Context context, AssetFile assetFile, Stream str foreach (var file in assetFile.Source) { + if (file.Condition != null) + { + var _fetchConditionKey = file.Condition.Key; + var _fetchConditionValue = file.Condition.Value; + + var _fetchConditionMain = context.Metadata.Preferences.FirstOrDefault(x => x.Key == _fetchConditionKey); + + if (_fetchConditionMain != null && !Object.Equals(_fetchConditionValue, _fetchConditionMain.Value)) + return; + } + if (!Enum.TryParse(file.Type, true, out var barEntryType)) throw new Exception($"BinArc type {file.Type} not recognized"); diff --git a/OpenKh.Research.Interceptor/OpenKh.Research.Interceptor.vcxproj b/OpenKh.Research.Interceptor/OpenKh.Research.Interceptor.vcxproj new file mode 100644 index 000000000..afff8fde8 --- /dev/null +++ b/OpenKh.Research.Interceptor/OpenKh.Research.Interceptor.vcxproj @@ -0,0 +1,148 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 18.0 + Win32Proj + {b74a4f17-8d09-44a7-a94b-51d642b60a60} + OpenKhCommandInterceptor + 10.0 + + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Windows + true + mainCRTStartup + + + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + true + + + + + + + + + \ No newline at end of file diff --git a/OpenKh.Research.Interceptor/OpenKh.Research.Interceptor.vcxproj.filters b/OpenKh.Research.Interceptor/OpenKh.Research.Interceptor.vcxproj.filters new file mode 100644 index 000000000..ce0c35ccf --- /dev/null +++ b/OpenKh.Research.Interceptor/OpenKh.Research.Interceptor.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/OpenKh.Research.Interceptor/main.cpp b/OpenKh.Research.Interceptor/main.cpp new file mode 100644 index 000000000..db57f95b1 --- /dev/null +++ b/OpenKh.Research.Interceptor/main.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +static map MAP_NAMES = +{ + {"kh1", "KINGDOM HEARTS FINAL MIX.exe" }, + {"kh2", "KINGDOM HEARTS II FINAL MIX.exe" }, + {"recom", "KINGDOM HEARTS Re_Chain of Memories.exe" }, + {"bbs", "KINGDOM HEARTS Birth by Sleep FINAL MIX.exe" }, + {"kh3d", "KINGDOM HEARTS Dream Drop Distance.exe" }, +}; + +static string SELF_NAME = "KINGDOM HEARTS HD 1.5+2.5 ReMIX.exe"; +static string REAL_NAME = "KINGDOM HEARTS HD 1.5+2.5 ReMIX.bak"; + +static string ARGUMENT_FETCH = "launch_args.txt"; + +int main(int argc, char* argv[]) +{ + auto _fetchHandle = GetConsoleWindow(); + ShowWindow(_fetchHandle, SW_HIDE); + + wchar_t _fetchPath[MAX_PATH]; + + auto _fetchLength = GetModuleFileNameW(nullptr, _fetchPath, MAX_PATH); + auto _fetchPathFS = filesystem::path(_fetchPath).parent_path().string(); + + auto _fetchArgsPath = _fetchPathFS + "\\" + ARGUMENT_FETCH; + + auto _fetchSelfPath = "\"" + _fetchPathFS + "\\" + SELF_NAME + "\""; + auto _fetchRealPath = "\"" + _fetchPathFS + "\\" + REAL_NAME + "\""; + + string _makeCommand; + + if (filesystem::exists(_fetchArgsPath)) + { + ifstream _fetchFile(_fetchArgsPath); + + stringstream _fetchBuff; + _fetchBuff << _fetchFile.rdbuf(); + + string _currArg; + vector _fetchArgs; + + while (getline(_fetchBuff, _currArg, ' ')) + _fetchArgs.push_back(_currArg); + + if (_fetchArgs.size() >= 0x01) + { + if (_fetchArgs[0] == "kh3d") + { + SELF_NAME = "KINGDOM HEARTS HD 2.8 Final Chapter Prologue.exe"; + REAL_NAME = "KINGDOM HEARTS HD 2.8 Final Chapter Prologue.bak"; + + _fetchSelfPath = "\"" + _fetchPathFS + "\\" + SELF_NAME + "\""; + _fetchRealPath = "\"" + _fetchPathFS + "\\" + REAL_NAME + "\""; + } + + _makeCommand = "\"" + _fetchPathFS + "\\" + MAP_NAMES[_fetchArgs[0]] + "\""; + + for (int i = 1; i < _fetchArgs.size(); i++) + { + _makeCommand += " "; + _makeCommand += _fetchArgs[i]; + } + + for (int i = 1; i < argc; i++) + { + if (argv[i] == "%command%") + continue; + + _makeCommand += " "; + _makeCommand += argv[i]; + } + + system(_makeCommand.c_str()); + } + } + + if (filesystem::exists(_fetchArgsPath)) + filesystem::remove(_fetchArgsPath); + + system(string("RENAME " + _fetchSelfPath + " \"delete.this\"").c_str()); + system(string("RENAME " + _fetchRealPath + " \"" + SELF_NAME + "\"").c_str()); + + return 0; +} diff --git a/OpenKh.Tests.Commands/BdxAntlrGrammarTests.cs b/OpenKh.Tests.Commands/BdxAntlrGrammarTests.cs index 66b15c25b..25e7a00ad 100644 --- a/OpenKh.Tests.Commands/BdxAntlrGrammarTests.cs +++ b/OpenKh.Tests.Commands/BdxAntlrGrammarTests.cs @@ -1,5 +1,5 @@ using Antlr4.Runtime; -using OpenKh.Command.Bdxio.Models; +using OpenKh.Kh2.Bdx.Models; using System.Collections.Generic; using System.Linq; using Xunit; diff --git a/OpenKh.Tests.Commands/BdxMassiveTests.cs b/OpenKh.Tests.Commands/BdxMassiveTests.cs index 5b8561fdd..3f4f65d3a 100644 --- a/OpenKh.Tests.Commands/BdxMassiveTests.cs +++ b/OpenKh.Tests.Commands/BdxMassiveTests.cs @@ -1,6 +1,6 @@ -using OpenKh.Command.Bdxio.Utils; using OpenKh.Common; using OpenKh.Kh2; +using OpenKh.Kh2.Bdx.Utils; using System; using System.Collections.Generic; using System.IO; diff --git a/OpenKh.Tests.Commands/BdxRegressionTests.cs b/OpenKh.Tests.Commands/BdxRegressionTests.cs index e3dd47210..e08340a81 100644 --- a/OpenKh.Tests.Commands/BdxRegressionTests.cs +++ b/OpenKh.Tests.Commands/BdxRegressionTests.cs @@ -1,5 +1,6 @@ -using OpenKh.Command.Bdxio.Models; -using OpenKh.Command.Bdxio.Utils; + +using OpenKh.Kh2.Bdx.Utils; +using OpenKh.Kh2.Bdx.Models; using System; using System.Collections.Generic; using System.Globalization; diff --git a/OpenKh.Tests.Commands/OpenKh.Tests.Commands.csproj b/OpenKh.Tests.Commands/OpenKh.Tests.Commands.csproj index 437e940eb..8026fbec1 100644 --- a/OpenKh.Tests.Commands/OpenKh.Tests.Commands.csproj +++ b/OpenKh.Tests.Commands/OpenKh.Tests.Commands.csproj @@ -20,7 +20,6 @@ - diff --git a/OpenKh.Tests/Patcher/MetadataTests.cs b/OpenKh.Tests/Patcher/MetadataTests.cs index 0094a09ac..01e4f8941 100644 --- a/OpenKh.Tests/Patcher/MetadataTests.cs +++ b/OpenKh.Tests/Patcher/MetadataTests.cs @@ -7,38 +7,6 @@ namespace OpenKh.Tests.Patcher { public class MetadataTests { - [Fact] - public void ReadModMetadataTest() - { - var metadata = File.OpenRead("Patcher/res/sample-simple-mod.yml").Using(Metadata.Read); - Assert.Equal("My awesome untitled mod", metadata.Title); - Assert.Equal(1, metadata.Specifications); - - Assert.Single(metadata.Dependencies); - Assert.Equal("openkh/is-awesome", metadata.Dependencies[0].Name); - - Assert.NotNull(metadata.Assets); - Assert.Single(metadata.Assets); - Assert.Equal("my/file/path.bin", metadata.Assets[0].Name); - } - - [Fact] - public void ReadModMetadataTestCollectionOptional() - { - var metadata = File.OpenRead("Patcher/res/sample-simple-collection-mod.yml").Using(Metadata.Read); - - Assert.Equal("My awesome untitled mod - part 2", metadata.Title); - Assert.Equal(1, metadata.Specifications); - - Assert.NotNull(metadata.Assets); - Assert.Equal(3, metadata.Assets.Count); - foreach (var asset in metadata.Assets) - { - Assert.IsType(asset); - Assert.Contains(asset.Game, metadata.CollectionGames); - } - Assert.True(metadata.Assets[2].CollectionOptional); - } } } diff --git a/OpenKh.Tests/Patcher/PatcherTests.cs b/OpenKh.Tests/Patcher/PatcherTests.cs index 891f157e1..178d71bc9 100644 --- a/OpenKh.Tests/Patcher/PatcherTests.cs +++ b/OpenKh.Tests/Patcher/PatcherTests.cs @@ -1,8 +1,8 @@ using OpenKh.Bbs; -using OpenKh.Command.Bdxio.Utils; using OpenKh.Common; using OpenKh.Imaging; using OpenKh.Kh2; +using OpenKh.Kh2.Bdx.Utils; using OpenKh.Kh2.Messages; using OpenKh.Patcher; using System; @@ -16,4435 +16,6 @@ namespace OpenKh.Tests.Patcher { - public class PatcherTests : IDisposable - { - private const string AssetsInputDir = "original_input"; - private const string ModInputDir = "mod_input"; - private const string ModOutputDir = "mod_output"; - - public PatcherTests() - { - Dispose(); - Directory.CreateDirectory(AssetsInputDir); - Directory.CreateDirectory(ModInputDir); - Directory.CreateDirectory(ModOutputDir); - } - - public void Dispose() - { - if (Directory.Exists(AssetsInputDir)) - Directory.Delete(AssetsInputDir, true); - if (Directory.Exists(ModInputDir)) - Directory.Delete(ModInputDir, true); - if (Directory.Exists(ModOutputDir)) - Directory.Delete(ModOutputDir, true); - } - - [Fact] - public void Kh2CopyBinariesTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bin", - Method = "copy", - Source = new List - { - new AssetFile - { - Name = "somedir/somefile.bin" - } - } - } - } - }; - - CreateFile(ModInputDir, patch.Assets[0].Name).Dispose(); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2CreateBinArcIfSourceDoesntExistsTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "abcd", - Type = "list", - Method = "copy", - Source = new List - { - new AssetFile - { - Name = "somedir/somefile/abcd.bin" - } - } - } - } - } - } - }; - - CreateFile(ModInputDir, "somedir/somefile/abcd.bin").Using(x => - { - x.WriteByte(0); - x.WriteByte(1); - x.WriteByte(2); - x.WriteByte(3); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("abcd", entry => - { - Assert.Equal(Bar.EntryType.List, entry.Type); - Assert.Equal(4, entry.Stream.Length); - Assert.Equal(0, entry.Stream.ReadByte()); - Assert.Equal(1, entry.Stream.ReadByte()); - Assert.Equal(2, entry.Stream.ReadByte()); - Assert.Equal(3, entry.Stream.ReadByte()); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2MergeWithOriginalBinArcTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "abcd", - Type = "list", - Method = "copy", - Source = new List - { - new AssetFile - { - Name = "somedir/somefile/abcd.bin" - } - } - } - } - } - } - }; - - CreateFile(ModInputDir, "somedir/somefile/abcd.bin").Using(x => - { - x.WriteByte(0); - x.WriteByte(1); - x.WriteByte(2); - x.WriteByte(3); - }); - - CreateFile(AssetsInputDir, "somedir/somefile.bar").Using(x => - { - Bar.Write(x, new Bar - { - new Bar.Entry - { - Name = "nice", - Type = Bar.EntryType.Model, - Stream = new MemoryStream(new byte[] { 4, 5, 6, 7 }) - } - }); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("abcd", entry => - { - Assert.Equal(Bar.EntryType.List, entry.Type); - Assert.Equal(4, entry.Stream.Length); - Assert.Equal(0, entry.Stream.ReadByte()); - Assert.Equal(1, entry.Stream.ReadByte()); - Assert.Equal(2, entry.Stream.ReadByte()); - Assert.Equal(3, entry.Stream.ReadByte()); - }, ModOutputDir, patch.Assets[0].Name); - AssertBarFile("nice", entry => - { - Assert.Equal(Bar.EntryType.Model, entry.Type); - Assert.Equal(4, entry.Stream.Length); - Assert.Equal(4, entry.Stream.ReadByte()); - Assert.Equal(5, entry.Stream.ReadByte()); - Assert.Equal(6, entry.Stream.ReadByte()); - Assert.Equal(7, entry.Stream.ReadByte()); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2CreateImgdTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "test", - Method = "imgd", - Type = "imgd", - Source = new List - { - new AssetFile - { - Name = "sample.png", - IsSwizzled = false - } - } - } - } - } - } - }; - - File.Copy("Imaging/res/png/32.png", Path.Combine(ModInputDir, "sample.png")); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("test", entry => - { - Assert.True(Imgd.IsValid(entry.Stream)); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void Kh2MergeImzTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "out.imz", - Method = "imgz", - Source = new List - { - new AssetFile - { - Name = "test.imd", - Index = 1, - } - } - } - } - }; - - var tmpImd = Imgd.Create(new System.Drawing.Size(16, 16), PixelFormat.Indexed4, new byte[16 * 16 / 2], new byte[4], false); - var patchImd = Imgd.Create(new System.Drawing.Size(32, 16), PixelFormat.Indexed4, new byte[32 * 16 / 2], new byte[4], false); - CreateFile(AssetsInputDir, "out.imz").Using(x => - { - Imgz.Write(x, new Imgd[] - { - tmpImd, - tmpImd, - tmpImd, - }); - }); - CreateFile(ModInputDir, "test.imd").Using(patchImd.Write); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "out.imz"); - File.OpenRead(Path.Combine(ModOutputDir, "out.imz")).Using(x => - { - var images = Imgz.Read(x).ToList(); - Assert.Equal(3, images.Count); - Assert.Equal(16, images[0].Size.Width); - Assert.Equal(32, images[1].Size.Width); - Assert.Equal(16, images[2].Size.Width); - }); - } - - [Fact] - public void Kh2MergeImzInsideBarTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "out.bar", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "test", - Type = "imgz", - Method = "imgz", - Source = new List - { - new AssetFile - { - Name = "test.imd", - Index = 1 - } - }, - } - } - } - } - }; - - var tmpImd = Imgd.Create(new System.Drawing.Size(16, 16), PixelFormat.Indexed4, new byte[16 * 16 / 2], new byte[4], false); - var patchImd = Imgd.Create(new System.Drawing.Size(32, 16), PixelFormat.Indexed4, new byte[32 * 16 / 2], new byte[4], false); - CreateFile(AssetsInputDir, "out.bar").Using(x => - { - using var memoryStream = new MemoryStream(); - Imgz.Write(memoryStream, new Imgd[] - { - tmpImd, - tmpImd, - tmpImd, - }); - - Bar.Write(x, new Bar - { - new Bar.Entry - { - Name = "test", - Type = Bar.EntryType.Imgz, - Stream = memoryStream - } - }); - }); - CreateFile(ModInputDir, "test.imd").Using(patchImd.Write); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "out.bar"); - AssertBarFile("test", x => - { - var images = Imgz.Read(x.Stream).ToList(); - Assert.Equal(3, images.Count); - Assert.Equal(16, images[0].Size.Width); - Assert.Equal(32, images[1].Size.Width); - Assert.Equal(16, images[2].Size.Width); - }, ModOutputDir, "out.bar"); - } - - [Fact] - public void MergeKh2MsgTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "msg/us/sys.msg", - Method = "kh2msg", - Source = new List - { - new AssetFile - { - Name = "sys.yml", - Language = "en", - } - } - }, - new AssetFile - { - Name = "msg/it/sys.msg", - Method = "kh2msg", - Source = new List - { - new AssetFile - { - Name = "sys.yml", - Language = "it", - } - } - }, - new AssetFile - { - Name = "msg/jp/sys.msg", - Method = "kh2msg", - Source = new List - { - new AssetFile - { - Name = "sys.yml", - Language = "jp", - } - } - } - } - }; - - Directory.CreateDirectory(Path.Combine(AssetsInputDir, "msg/us/")); - File.Create(Path.Combine(AssetsInputDir, "msg/us/sys.msg")).Using(stream => - { - Msg.Write(stream, new List - { - new Msg.Entry - { - Data = new byte[] { 1, 2, 3, 0 }, - Id = 123 - } - }); - }); - File.Create(Path.Combine(ModInputDir, "sys.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- id: 456"); - writer.WriteLine(" en: English"); - writer.WriteLine(" it: Italiano"); - writer.WriteLine(" jp: テスト"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "msg/jp/sys.msg"); - File.OpenRead(Path.Combine(ModOutputDir, "msg/jp/sys.msg")).Using(stream => - { - var msg = Msg.Read(stream); - Assert.Single(msg); - Assert.Equal(456, msg[0].Id); - Assert.Equal("テスト", Encoders.JapaneseSystem.Decode(msg[0].Data).First().Text); - }); - - AssertFileExists(ModOutputDir, "msg/us/sys.msg"); - File.OpenRead(Path.Combine(ModOutputDir, "msg/us/sys.msg")).Using(stream => - { - var msg = Msg.Read(stream); - Assert.Equal(2, msg.Count); - Assert.Equal(123, msg[0].Id); - Assert.Equal(456, msg[1].Id); - Assert.Equal("English", Encoders.InternationalSystem.Decode(msg[1].Data).First().Text); - }); - - AssertFileExists(ModOutputDir, "msg/it/sys.msg"); - File.OpenRead(Path.Combine(ModOutputDir, "msg/it/sys.msg")).Using(stream => - { - var msg = Msg.Read(stream); - Assert.Single(msg); - Assert.Equal(456, msg[0].Id); - Assert.Equal("Italiano", Encoders.InternationalSystem.Decode(msg[0].Data).First().Text); - }); - } - - [Fact] - public void MergeKh2AreaDataScriptTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "map.script", - Method = "areadatascript", - Source = new List - { - new AssetFile - { - Name = "map.txt", - } - } - }, - } - }; - - File.Create(Path.Combine(AssetsInputDir, "map.script")).Using(stream => - { - var compiledProgram = Kh2.Ard.AreaDataScript.Compile("Program 1\nSpawn \"1111\""); - Kh2.Ard.AreaDataScript.Write(stream, compiledProgram); - }); - File.Create(Path.Combine(ModInputDir, "map.txt")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("Program 2"); - writer.WriteLine("Spawn \"2222\""); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "map.script"); - File.OpenRead(Path.Combine(ModOutputDir, "map.script")).Using(stream => - { - var scripts = Kh2.Ard.AreaDataScript.Read(stream); - var decompiled = Kh2.Ard.AreaDataScript.Decompile(scripts); - decompiled.Contains("Program 1"); - decompiled.Contains("Spawn \"1111\""); - decompiled.Contains("Program 2"); - decompiled.Contains("Spawn \"2222\""); - }); - } - - [Fact] - public void PatchKh2BdscriptTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "aaa", - Method = "bdscript", - Source = new List - { - new AssetFile - { - Name = "test.bdscript", - } - } - }, - } - }; - File.Create(Path.Combine(ModInputDir, "test.bdscript")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("---"); - writer.WriteLine("WorkSize: 64"); - writer.WriteLine("StackSize: 64"); - writer.WriteLine("TempSize: 64"); - writer.WriteLine("Triggers:"); - writer.WriteLine("- Key: 0"); - writer.WriteLine(" Addr: TR0"); - writer.WriteLine("Name: aaa"); - writer.WriteLine("---"); - writer.WriteLine(" section .text"); - writer.WriteLine("TR0:"); - writer.WriteLine(" ret"); - writer.WriteLine("DUMMY:"); - writer.WriteLine(" ret"); - writer.Flush(); - }); - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "aaa"); - - var bdxStream = new MemoryStream(File.ReadAllBytes(Path.Combine(ModOutputDir, "aaa"))); - var decoder = new BdxDecoder(bdxStream); - var script = BdxDecoder.TextFormatter.Format(decoder); - - var lines = script.Split("\r\n"); - - Assert.Equal("WorkSize: 64", lines[1]); - Assert.Equal("Name: aaa", lines[7]); - - } - - [Fact] - public void PatchKh2SpawnPointTest() - { - - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "map.script", - Method = "areadataspawn", - Source = new List - { - new AssetFile - { - Name = "map.yaml", - } - } - }, - } - }; - - File.Create(Path.Combine(AssetsInputDir, "map.script")).Using(stream => - { - var spawnPoint = new List(); - - Kh2.Ard.SpawnPoint.Write(stream, spawnPoint); - }); - File.Create(Path.Combine(ModInputDir, "map.yaml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Type: 2"); - writer.WriteLine(" Flag: 1"); - writer.Flush(); - }); - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "map.script"); - var content = File.ReadAllText(Path.Combine(ModOutputDir, "map.script")); - var scripts = new Deserializer().Deserialize> (content); - - Assert.Equal(2, scripts[0].Type); - Assert.Equal(1, scripts[0].Flag); - - } - - - public void ListPatchTrsrTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "trsr", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "TrsrList.yml", - Type = "trsr" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bar")).Using(stream => - { - var trsrEntry = new List() - { - new Kh2.SystemData.Trsr - { - Id = 1, - ItemId = 10 - } - }; - using var trsrStream = new MemoryStream(); - Kh2.SystemData.Trsr.Write(trsrStream, trsrEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "trsr", - Type = Bar.EntryType.List, - Stream = trsrStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "TrsrList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("1:"); - writer.WriteLine(" ItemId: 200"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var trsrStream = Kh2.SystemData.Trsr.Read(binarc[0].Stream); - Assert.Equal(200, trsrStream[0].ItemId); - }); - - } - - [Fact] - public void ListPatchCmdTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "cmd", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "CmdList.yml", - Type = "cmd" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bar")).Using(stream => - { - var cmdEntry = new List() - { - new Kh2.SystemData.Cmd - { - Id = 1, - Execute = 3, - Argument = 3, - SubMenu = 1, - } - }; - using var cmdStream = new MemoryStream(); - Kh2.SystemData.Cmd.Write(cmdStream, cmdEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "cmd", - Type = Bar.EntryType.List, - Stream = cmdStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "CmdList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Id: 1"); - writer.WriteLine(" Execute: 3"); - writer.WriteLine(" Argument: 3"); - writer.WriteLine(" SubMenu: 1"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var cmdStream = Kh2.SystemData.Cmd.Read(binarc[0].Stream); - Assert.Equal(1, cmdStream[0].Id); - Assert.Equal(3, cmdStream[0].Execute); - Assert.Equal(3, cmdStream[0].Argument); - Assert.Equal(1, cmdStream[0].SubMenu); - }); - - } - - [Fact] - public void ListPatchItemTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "item", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "ItemList.yml", - Type = "item" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bar")).Using(stream => - { - var itemEntry = new List() - { - new Kh2.SystemData.Item - { - Items = new List() - { - new Kh2.SystemData.Item.Entry() - { - Id = 1, - ShopBuy = 10 - } - }, - Stats = new List() - { - new Kh2.SystemData.Item.Stat() - { - Id = 10, - Ability = 15 - } - } - - } - }; - using var itemStream = new MemoryStream(); - itemEntry[0].Write(itemStream); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "item", - Type = Bar.EntryType.List, - Stream = itemStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "ItemList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("Items:"); - writer.WriteLine("- Id: 1"); - writer.WriteLine(" ShopBuy: 200"); - writer.WriteLine("Stats:"); - writer.WriteLine("- Id: 10"); - writer.WriteLine(" Ability: 150"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var itemStream = Kh2.SystemData.Item.Read(binarc[0].Stream); - Assert.Equal(200, itemStream.Items[0].ShopBuy); - Assert.Equal(150, itemStream.Stats[0].Ability); - }); - - } - - [Fact] - public void ListPatchShopTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "03system.bin", - Method = "binarc", - Source = new List - { - new AssetFile - { - Name = "shop", - Method = "listpatch", - Type = "Unknown41", - Source = new List - { - new AssetFile - { - Name = "ShopList.yml", - Type = "shop" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bin")).Using(stream => - { - var shop = new OpenKh.Kh2.SystemData.Shop - { - ShopEntries = new List - { - new OpenKh.Kh2.SystemData.Shop.ShopEntry - { - CommandArgument = 0x0067, - UnlockMenuFlag = 0x0029, - NameID = 0x8AB8, - ShopKeeperEntityID = 0x0539, - PosX = 0x008B, - PosY = 0x006C, - PosZ = -576, //0xFDC0, - ExtraInventoryBitMask = 0x81, - SoundID = 0x01, - InventoryCount = 0x0001, - ShopID = 0x00, - Unk19 = 0x02, - InventoryOffset = 0x0028, - Reserved = 0x00 - } - }, - InventoryEntries = new List - { - new OpenKh.Kh2.SystemData.Shop.InventoryEntry - { - UnlockEventID = 0xFFFF, - ProductCount = 0x0002, - ProductOffset = 0x0030, - Reserved = 0x00 - } - }, - ProductEntries = new List - { - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x0094 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x008B - }, - }, - ValidProductEntries = new List - { - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x0094 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x008B - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x0000 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x0000 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x0000 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntry - { - ItemID = 0x0000 - } - } - }; - - using var shopStream = new MemoryStream(); - OpenKh.Kh2.SystemData.Shop.Write(shopStream, shop); - Bar.Write(stream, new Bar { - new Bar.Entry - { - Name = "shop", - Type = Bar.EntryType.Unknown41, - Stream = shopStream - } - }); - }); - - var moddedShop = new OpenKh.Kh2.SystemData.Shop.ShopHelper - { - ShopEntryHelpers = new List - { - new OpenKh.Kh2.SystemData.Shop.ShopEntryHelper - { - CommandArgument = 0x0068, - UnlockMenuFlag = 0x002A, - NameID = 0x8AB9, - ShopKeeperEntityID = 0x0749, - PosX = 0x0086, - PosY = 0x0096, - PosZ = -591, // 0xFDB1, - ExtraInventoryBitMask = 0x82, - SoundID = 0x01, - InventoryCount = 0x0001, - ShopID = 0x00, - Unk19 = 0x02, - InventoryStartIndex = 0 - } - }, - InventoryEntryHelpers = new List - { - new OpenKh.Kh2.SystemData.Shop.InventoryEntryHelper - { - InventoryIndex = 0, - UnlockEventID = 0xFFFF, - ProductCount = 0x0002, - ProductStartIndex = 0, - } - }, - ProductEntryHelpers = new List - { - new OpenKh.Kh2.SystemData.Shop.ProductEntryHelper - { - ProductIndex = 0, - ItemID = 0x0043 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntryHelper - { - ProductIndex = 1, - ItemID = 0x0128 - } - }, - ValidProductEntryHelpers = new List - { - new OpenKh.Kh2.SystemData.Shop.ProductEntryHelper - { - ProductIndex = 0, - ItemID = 0x0043 - }, - new OpenKh.Kh2.SystemData.Shop.ProductEntryHelper - { - ProductIndex = 1, - ItemID = 0x0128 - } - } - }; - - File.Create(Path.Combine(ModInputDir, "ShopList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - - var serializer = new Serializer(); - - writer.Write(serializer.Serialize(moddedShop)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bin")).Using(stream => - { - var binarc = Bar.Read(stream); - var verifyShop = OpenKh.Kh2.SystemData.Shop.Read(binarc[0].Stream); - uint inventoryEntriesBaseOffset = (uint)(OpenKh.Kh2.SystemData.Shop.HeaderSize + verifyShop.ShopEntries.Count * OpenKh.Kh2.SystemData.Shop.ShopEntrySize); - uint productEntriesBaseOffset = (uint)(inventoryEntriesBaseOffset + verifyShop.InventoryEntries.Count * OpenKh.Kh2.SystemData.Shop.InventoryEntrySize); - foreach (var shopEntryHelper in moddedShop.ShopEntryHelpers) - { - int shopID = shopEntryHelper.ShopID; - Assert.Equal(verifyShop.ShopEntries[shopID].CommandArgument, shopEntryHelper.CommandArgument); - Assert.Equal(verifyShop.ShopEntries[shopID].UnlockMenuFlag, shopEntryHelper.UnlockMenuFlag); - Assert.Equal(verifyShop.ShopEntries[shopID].NameID, shopEntryHelper.NameID); - Assert.Equal(verifyShop.ShopEntries[shopID].ShopKeeperEntityID, shopEntryHelper.ShopKeeperEntityID); - Assert.Equal(verifyShop.ShopEntries[shopID].PosX, shopEntryHelper.PosX); - Assert.Equal(verifyShop.ShopEntries[shopID].PosY, shopEntryHelper.PosY); - Assert.Equal(verifyShop.ShopEntries[shopID].PosZ, shopEntryHelper.PosZ); - Assert.Equal(verifyShop.ShopEntries[shopID].ExtraInventoryBitMask, shopEntryHelper.ExtraInventoryBitMask); - Assert.Equal(verifyShop.ShopEntries[shopID].SoundID, shopEntryHelper.SoundID); - Assert.Equal(verifyShop.ShopEntries[shopID].InventoryCount, shopEntryHelper.InventoryCount); - Assert.Equal(verifyShop.ShopEntries[shopID].ShopID, shopEntryHelper.ShopID); - Assert.Equal(verifyShop.ShopEntries[shopID].Unk19, shopEntryHelper.Unk19); - Assert.Equal(verifyShop.ShopEntries[shopID].InventoryOffset, (int)(inventoryEntriesBaseOffset + shopEntryHelper.InventoryStartIndex * OpenKh.Kh2.SystemData.Shop.InventoryEntrySize)); - } - foreach (var inventoryEntryHelper in moddedShop.InventoryEntryHelpers) - { - Assert.Equal(verifyShop.InventoryEntries[inventoryEntryHelper.InventoryIndex].UnlockEventID, inventoryEntryHelper.UnlockEventID); - Assert.Equal(verifyShop.InventoryEntries[inventoryEntryHelper.InventoryIndex].ProductCount, inventoryEntryHelper.ProductCount); - Assert.Equal(verifyShop.InventoryEntries[inventoryEntryHelper.InventoryIndex].ProductOffset, (int)(productEntriesBaseOffset + inventoryEntryHelper.ProductStartIndex * OpenKh.Kh2.SystemData.Shop.ProductEntrySize)); - } - foreach (var productEntryHelper in moddedShop.ProductEntryHelpers) - { - Assert.Equal(verifyShop.ProductEntries[productEntryHelper.ProductIndex].ItemID, productEntryHelper.ItemID); - } - foreach (var productEntryHelper in moddedShop.ValidProductEntryHelpers) - { - Assert.Equal(verifyShop.ValidProductEntries[productEntryHelper.ProductIndex].ItemID, productEntryHelper.ItemID); - } - }); - } - - [Fact] - public void ListPatchSkltTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "sklt", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "SkltList.yml", - Type = "sklt" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bar")).Using(stream => - { - var skltEntry = new List() - { - new Kh2.SystemData.Sklt - { - CharacterId = 1, - Bone1 = 178, - Bone2 = 86 - } - }; - - using var skltStream = new MemoryStream(); - Kh2.SystemData.Sklt.Write(skltStream, skltEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "sklt", - Type = Bar.EntryType.List, - Stream = skltStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "SkltList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- CharacterId: 1"); - writer.WriteLine(" Bone1: 178"); - writer.WriteLine(" Bone2: 86"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var skltStream = Kh2.SystemData.Sklt.Read(binarc[0].Stream); - Assert.Equal(1U, skltStream[0].CharacterId); - Assert.Equal(178, skltStream[0].Bone1); - Assert.Equal(86, skltStream[0].Bone2); - }); - } - - [Fact] //Fixed, needed to initialize the BGMSet & Reserved bytes. - public void ListPatchArifTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bin", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "arif", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "ArifList.yml", - Type = "arif" - } - } - } - } - } - } - }; - - using (var stream = File.Create(Path.Combine(AssetsInputDir, "03system.bin"))) - { - var arifEntry = new Kh2.SystemData.Arif - { - Flags = Kh2.SystemData.Arif.ArifFlags.IsKnownArea, - Reverb = 0, - SoundEffectBank1 = 13, - SoundEffectBank2 = 0, - Bgms = Enumerable.Range(0, 8).Select(_ => new Kh2.SystemData.BgmSet { BgmField = 0, BgmBattle = 0 }).ToArray(), - Voice = 0, - NavigationMapItem = 0, - Command = 0, - Reserved = new byte[11] - }; - - using (var arifStream = new MemoryStream()) - { - Kh2.SystemData.Arif.Write(arifStream, new List> { new List { arifEntry } }); - Bar.Write(stream, new Bar - { - new Bar.Entry() - { - Name = "arif", - Type = Bar.EntryType.List, - Stream = arifStream - } - }); - } - } - - File.Create(Path.Combine(ModInputDir, "ArifList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("EndOfSea:"); - writer.WriteLine(" 1:"); - writer.WriteLine(" SoundEffectBank1: 13"); - writer.WriteLine(" Voice: 0"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bin")).Using(stream => - { - var binarc = Bar.Read(stream); - var arifList = Kh2.SystemData.Arif.Read(binarc[0].Stream); - var arifEntry = arifList[0][0]; - Assert.Equal(13, arifEntry.SoundEffectBank1); - Assert.Equal(0, arifEntry.Voice); - }); - } - - [Fact] - public void ListPatchMemtTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "memt", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "MemtList.yml", - Type = "memt" - } - } - } - } - } - } - }; - - // Create the 03system.bar file with initial data - File.Create(Path.Combine(AssetsInputDir, "03system.bar")).Using(stream => - { - var memtEntries = new List() - { - new Kh2.SystemData.Memt.EntryFinalMix - { - WorldId = 1, - CheckStoryFlag = 1, - CheckStoryFlagNegation = 0, - CheckArea = 0, - Padding = 0, - PlayerSize= 0, - FriendSize = 0, - Members = new short[18] - } - }; - - var memberIndices = new Kh2.SystemData.Memt.MemberIndices[7]; // Ensure there are 7 MemberIndices - for (int i = 0; i < memberIndices.Length; i++) - { - memberIndices[i] = new Kh2.SystemData.Memt.MemberIndices - { - Player = 0, - Friend1 = 0, - Friend2 = 0, - FriendWorld = 0 - }; - } - - using var memtStream = new MemoryStream(); - var memt = new Kh2.SystemData.Memt(); - memt.Entries.AddRange(memtEntries.Cast()); - - Kh2.SystemData.Memt.Write(memtStream, memt); - memtStream.Seek(0, SeekOrigin.Begin); - - Bar.Write(stream, new Bar() - { - new Bar.Entry() - { - Name = "memt", - Type = Bar.EntryType.List, - Stream = memtStream - } - }); - }); - - // Create the MemtList.yml patch file - File.Create(Path.Combine(ModInputDir, "MemtList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("MemtEntries:"); - writer.WriteLine(" - Index: 0"); - writer.WriteLine(" WorldId: 2"); - writer.WriteLine(" CheckStoryFlag: 3"); - writer.WriteLine(" CheckStoryFlagNegation: 4"); - writer.WriteLine(" CheckArea: 5"); - writer.WriteLine(" Padding: 6"); - writer.WriteLine(" PlayerSize: 7"); - writer.WriteLine(" FriendSize: 8"); - writer.WriteLine(" Members: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]"); - writer.WriteLine("MemberIndices:"); - writer.WriteLine(" - Index: 0"); - writer.WriteLine(" Player: 0"); - writer.WriteLine(" Friend1: 0"); - writer.WriteLine(" Friend2: 0"); - writer.WriteLine(" FriendWorld: 0"); - writer.Flush(); - }); - - // Apply the patch - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir); - - // Verify the patched data - AssertFileExists(ModOutputDir, "03system.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var memtStream = binarc[0].Stream; - memtStream.Seek(0, SeekOrigin.Begin); - - var memt = Kh2.SystemData.Memt.Read(memtStream); - - var memtEntry = memt.Entries.Cast().First(); - Assert.Equal((short)2, memtEntry.WorldId); - Assert.Equal((short)3, memtEntry.CheckStoryFlag); - Assert.Equal((short)4, memtEntry.CheckStoryFlagNegation); - Assert.Equal((short)5, memtEntry.CheckArea); - Assert.Equal((short)6, memtEntry.Padding); - Assert.Equal((short)7, memtEntry.PlayerSize); - Assert.Equal((short)8, memtEntry.FriendSize); - Assert.Equal(new short[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 }, memtEntry.Members); - - // Check MemberIndices deserialization - var memberIndices = memt.MemberIndexCollection.First(); - Assert.Equal((byte)0, memberIndices.Player); - Assert.Equal((byte)0, memberIndices.Friend1); - Assert.Equal((byte)0, memberIndices.Friend2); - Assert.Equal((byte)0, memberIndices.FriendWorld); - }); - } - - - - - [Fact] - public void ListPatchFmabTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "pref", - Method = "binarc", - Type = "Binary", - Source = new List() - { - new AssetFile() - { - Name = "fmab", - Method = "listpatch", - Type = "list", - Source = new List() - { - new AssetFile() - { - Name = "FmabList.yml", - Type = "fmab" - } - } - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bar")).Using(stream => - { - var FmabEntry = new List() - { - new Kh2.SystemData.Fmab - { - HighJumpHeight = 178, - AirDodgeHeight = 86 - } - }; - - using var fmabStream = new MemoryStream(); - Kh2.SystemData.Fmab.Write(fmabStream, FmabEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "fmab", - Type = Bar.EntryType.List, - Stream = fmabStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "FmabList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- HighJumpHeight: 178"); - writer.WriteLine(" AirDodgeHeight: 86"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var fmabStream = Kh2.SystemData.Fmab.Read(binarc[0].Stream); - Assert.Equal(178, fmabStream[0].HighJumpHeight); - Assert.Equal(86, fmabStream[0].AirDodgeHeight); - }); - } - - [Fact] - public void ListPatchFmlvTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "fmlv", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "FmlvList.yml", - Type = "fmlv" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var fmlvEntry = new List() - { - new Kh2.Battle.Fmlv - { - FormId = 1, - FormLevel = 1, - Exp = 100, - Ability = 200 - }, - new Kh2.Battle.Fmlv - { - FormId = 1, - FormLevel = 2, - Exp = 100, - Ability = 200 - }, - new Kh2.Battle.Fmlv - { - FormId = 2, - FormLevel = 1, - Exp = 100, - Ability = 200 - }, - }; - - using var fmlvStream = new MemoryStream(); - Kh2.Battle.Fmlv.Write(fmlvStream, fmlvEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "fmlv", - Type = Bar.EntryType.List, - Stream = fmlvStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "FmlvList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var serializer = new Serializer(); - serializer.Serialize(writer, new Dictionary - { - ["Valor"] = new[] - { - new FmlvDTO - { - FormLevel = 1, - Experience = 5, - Ability = 127 - } - } - }); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var fmlv = Kh2.Battle.Fmlv.Read(binarc[0].Stream); - - Assert.Equal(3, fmlv.Count); - Assert.Equal(1, fmlv[0].FormId); - Assert.Equal(1, fmlv[0].FormLevel); - Assert.Equal(5, fmlv[0].Exp); - Assert.Equal(127, fmlv[0].Ability); - - Assert.Equal(1, fmlv[1].FormId); - Assert.Equal(2, fmlv[1].FormLevel); - - Assert.Equal(2, fmlv[2].FormId); - Assert.Equal(1, fmlv[2].FormLevel); - }); - } - - [Fact] - public void ListPatchBonsTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "bons", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "BonsList.yml", - Type = "bons" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var bonsEntry = new List() - { - new Kh2.Battle.Bons - { - CharacterId = 1, - RewardId = 15, - BonusItem1 = 10 - }, - new Kh2.Battle.Bons - { - CharacterId = 2, - RewardId = 15, - BonusItem1 = 5 - } - }; - using var bonsStream = new MemoryStream(); - Kh2.Battle.Bons.Write(bonsStream, bonsEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "bons", - Type = Bar.EntryType.List, - Stream = bonsStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "BonsList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("15:"); - writer.WriteLine(" Sora:"); - writer.WriteLine(" BonusItem1: 200"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var bonsStream = Kh2.Battle.Bons.Read(binarc[0].Stream); - Assert.Equal(200, bonsStream[0].BonusItem1); - Assert.Equal(5, bonsStream[1].BonusItem1); - }); - - } - - [Fact] - public void ListPatchLvupTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bin", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "lvup", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "LvupList.yml", - Type = "lvup" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bin")).Using(stream => - { - var lvupEntry = new Kh2.Battle.Lvup - { - Count = 13, - Unknown08 = new byte[0x38], - Characters = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - }, - new Kh2.Battle.Lvup.PlayableCharacter() - { - NumLevels = 1, - Levels = new List() - { - new Kh2.Battle.Lvup.PlayableCharacter.Level() - { - Exp = 50 - } - } - } - - } - }; - using var lvupStream = new MemoryStream(); - lvupEntry.Write(lvupStream); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "lvup", - Type = Bar.EntryType.List, - Stream = lvupStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "LvupList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("Sora:"); - writer.WriteLine(" 1:"); - writer.WriteLine(" Exp: 500"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bin")).Using(stream => - { - var binarc = Bar.Read(stream); - var lvupStream = Kh2.Battle.Lvup.Read(binarc[0].Stream); - Assert.Equal(500, lvupStream.Characters[0].Levels[0].Exp); - }); - - } - - [Fact] - void ListPatchAtkpTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "atkp", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "AtkpList.yml", - Type = "atkp" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var atkpEntry = new List() - { - new Kh2.Battle.Atkp - { - Id = 0, - SubId = 3, - Type = Kh2.Battle.Atkp.AttackType.PierceArmor, - CriticalAdjust = 0, - Power = 25, - Team = 0, - Element = 0, - EnemyReaction = 0, - EffectOnHit = 2, - KnockbackStrength1 = 32767, - KnockbackStrength2 = 0, - Unknown = 0, - Flags = Kh2.Battle.Atkp.AttackFlags.BGHit, - RefactSelf = Kh2.Battle.Atkp.Refact.Reflect, - RefactOther = Kh2.Battle.Atkp.Refact.Reflect, - ReflectedMotion = 0, - ReflectHitBack = 0, - ReflectAction = 0, - ReflectHitSound = 0, - ReflectRC = 0, - ReflectRange = 0, - ReflectAngle = 0, - DamageEffect = 0, - Switch = 1, - Interval = 1, - FloorCheck = 1, - DriveDrain = 1, - RevengeDamage = 1, - AttackTrReaction = Kh2.Battle.Atkp.TrReaction.Charge, - ComboGroup = 1, - RandomEffect = 1, - Kind = Kh2.Battle.Atkp.AttackKind.ComboFinisher, - HpDrain = 15 - } - }; - - using var atkpStream = new MemoryStream(); - Kh2.Battle.Atkp.Write(atkpStream, atkpEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "atkp", - Type = Bar.EntryType.List, - Stream = atkpStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "AtkpList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Id: 0"); - writer.WriteLine(" SubId: 3"); - writer.WriteLine(" Type: PierceArmor"); - writer.WriteLine(" CriticalAdjust: 0"); - writer.WriteLine(" Power: 25"); - writer.WriteLine(" Team: 0"); - writer.WriteLine(" Element: 0"); - writer.WriteLine(" EnemyReaction: 0"); - writer.WriteLine(" EffectOnHit: 2"); - writer.WriteLine(" KnockbackStrength1: 32767"); - writer.WriteLine(" KnockbackStrength2: 0"); - writer.WriteLine(" Unknown: 0"); - writer.WriteLine(" Flags: BGHit"); - writer.WriteLine(" RefactSelf: 0"); - writer.WriteLine(" RefactOther: 0"); - writer.WriteLine(" ReflectedMotion: 0"); - writer.WriteLine(" ReflectHitBack: 0"); - writer.WriteLine(" ReflectAction: 0"); - writer.WriteLine(" ReflectHitSound: 0"); - writer.WriteLine(" ReflectRC: 0"); - writer.WriteLine(" ReflectRange: 0"); - writer.WriteLine(" ReflectAngle: 0"); - writer.WriteLine(" DamageEffect: 0"); - writer.WriteLine(" Switch: 1"); - writer.WriteLine(" Interval: 1"); - writer.WriteLine(" FloorCheck: 1"); - writer.WriteLine(" DriveDrain: 1"); - writer.WriteLine(" RevengeDamage: 1"); - writer.WriteLine(" AttackTrReaction: 1"); - writer.WriteLine(" ComboGroup: 1"); - writer.WriteLine(" RandomEffect: 1"); - writer.WriteLine(" Kind: ComboFinisher"); - writer.WriteLine(" HpDrain: 15"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var atkpStream = Kh2.Battle.Atkp.Read(binarc[0].Stream); - Assert.Equal(0, atkpStream[0].Id); - Assert.Equal(3, atkpStream[0].SubId); - Assert.Equal(Kh2.Battle.Atkp.AttackType.PierceArmor, atkpStream[0].Type); - Assert.Equal(0, atkpStream[0].CriticalAdjust); - Assert.Equal(25, atkpStream[0].Power); - Assert.Equal(0, atkpStream[0].Team); - Assert.Equal(0, atkpStream[0].Element); - Assert.Equal(0, atkpStream[0].EnemyReaction); - Assert.Equal(2, atkpStream[0].EffectOnHit); - Assert.Equal(32767, atkpStream[0].KnockbackStrength1); - Assert.Equal(0, atkpStream[0].KnockbackStrength2); - Assert.Equal(0000, atkpStream[0].Unknown); - Assert.Equal(Kh2.Battle.Atkp.AttackFlags.BGHit, atkpStream[0].Flags); - Assert.Equal(Kh2.Battle.Atkp.Refact.Reflect, atkpStream[0].RefactSelf); - Assert.Equal(Kh2.Battle.Atkp.Refact.Reflect, atkpStream[0].RefactOther); - Assert.Equal(0, atkpStream[0].ReflectedMotion); - Assert.Equal(0, atkpStream[0].ReflectHitBack); - Assert.Equal(0, atkpStream[0].ReflectAction); - Assert.Equal(0, atkpStream[0].ReflectHitSound); - Assert.Equal(0, atkpStream[0].ReflectRC); - Assert.Equal(0, atkpStream[0].ReflectRange); - Assert.Equal(0, atkpStream[0].ReflectAngle); - Assert.Equal(0, atkpStream[0].DamageEffect); - Assert.Equal(1, atkpStream[0].Switch); - Assert.Equal(1, atkpStream[0].Interval); - Assert.Equal(1, atkpStream[0].FloorCheck); - Assert.Equal(1, atkpStream[0].DriveDrain); - Assert.Equal(1, atkpStream[0].RevengeDamage); - Assert.Equal(Kh2.Battle.Atkp.TrReaction.Charge, atkpStream[0].AttackTrReaction); - Assert.Equal(1, atkpStream[0].ComboGroup); - Assert.Equal(1, atkpStream[0].RandomEffect); - Assert.Equal(Kh2.Battle.Atkp.AttackKind.ComboFinisher, atkpStream[0].Kind); - Assert.Equal(15, atkpStream[0].HpDrain); - }); - } - - [Fact] - void ListPatchLvpmTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "lvpm", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "LvpmList.yml", - Type = "lvpm" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var lvpmEntry = new List() - { - new Kh2.Battle.Lvpm - { - HpMultiplier = 89, - Strength = 77, - Defense = 88, - MaxStrength = 40, - MinStrength = 32, - Experience = 777 - } - }; - - using var lvpmStream = new MemoryStream(); - Kh2.Battle.Lvpm.Write(lvpmStream, lvpmEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "lvpm", - Type = Bar.EntryType.List, - Stream = lvpmStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "LvpmList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - - var serializer = new Serializer(); - var moddedLvpm = new List{ - new Kh2.Battle.LvpmHelper - { - Level = 0, - HpMultiplier = 89, - Strength = 77, - Defense = 88, - MaxStrength = 40, - MinStrength = 32, - Experience = 777 - } - }; - writer.Write(serializer.Serialize(moddedLvpm)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var lvpmStream = Kh2.Battle.Lvpm.Read(binarc[0].Stream, 1); - var helperList = Kh2.Battle.LvpmHelper.ConvertLvpmListToHelper(lvpmStream); - Assert.Equal(0, helperList[0].Level); - Assert.Equal(89, helperList[0].HpMultiplier); - Assert.Equal(77, helperList[0].Strength); - Assert.Equal(88, helperList[0].Defense); - Assert.Equal(40, helperList[0].MaxStrength); - Assert.Equal(32, helperList[0].MinStrength); - Assert.Equal(777, helperList[0].Experience); - }); - } - - [Fact] - public void ListPatchPrztTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "przt", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "PrztList.yml", - Type = "przt" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var prztEntry = new List() - { - new Kh2.Battle.Przt - { - Id = 1, - SmallHpOrbs = 0, - BigHpOrbs = 1 - } - }; - - using var prztStream = new MemoryStream(); - Kh2.Battle.Przt.Write(prztStream, prztEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "przt", - Type = Bar.EntryType.List, - Stream = prztStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "PrztList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var serializer = new Serializer(); - var moddedPrzt = new List{ - new Kh2.Battle.Przt - { - Id = 1, - SmallHpOrbs = 0, - BigHpOrbs = 1 - } - }; - writer.Write(serializer.Serialize(moddedPrzt)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var przt = Kh2.Battle.Przt.Read(binarc[0].Stream); - - Assert.Equal(1, przt[0].BigHpOrbs); - }); - } - - - [Fact] - public void ListPatchObjEntryTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00objentry.bin", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "ObjList.yml", - Type = "objentry", - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00objentry.bin")).Using(stream => - { - var objEntry = new List() - { - new Kh2.Objentry - { - ObjectId = 1, - ModelName = "M_EX060", - AnimationName = "M_EX060.mset" - } - }; - Kh2.Objentry.Write(stream, objEntry); - }); - - File.Create(Path.Combine(ModInputDir, "ObjList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("1:"); - writer.WriteLine(" ObjectId: 1"); - writer.WriteLine(" ModelName: M_EX100"); - writer.WriteLine(" AnimationName: M_EX100.mset"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00objentry.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "00objentry.bin")).Using(stream => - { - var objStream = Kh2.Objentry.Read(stream); - Assert.Equal("M_EX100", objStream[0].ModelName); - Assert.Equal("M_EX100.mset", objStream[0].AnimationName); - }); - - } - - [Fact] - public void ListPatchPlrpTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "plrp", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "PlrpList.yml", - Type = "plrp" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var plrpEntry = new List() - { - new Kh2.Battle.Plrp - { - Id = 7, - Character = 1, - Ap = 2, - Items = new List(32), - Padding = new byte[52] - } - }; - - using var plrpStream = new MemoryStream(); - Kh2.Battle.Plrp.Write(plrpStream, plrpEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "plrp", - Type = Bar.EntryType.List, - Stream = plrpStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "PlrpList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var serializer = new Serializer(); - var moddedPlrp = new List{ - new Kh2.Battle.Plrp - { - Id = 7, - Character = 1, - Ap = 200, - Items = new List(32), - Padding = new byte[52] - } - }; - writer.Write(serializer.Serialize(moddedPlrp)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var plrp = Kh2.Battle.Plrp.Read(binarc[0].Stream); - - Assert.Equal(200, plrp[0].Ap); - }); - } - - [Fact] - public void ListPatchEnmpTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "enmp", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "EnmpList.yml", - Type = "enmp" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var enmpEntry = new List() - { - new Kh2.Battle.Enmp - { - Id = 7, - Level = 1, - Health = new short[32], - MaxDamage = 1, - MinDamage = 1, - PhysicalWeakness = 1, - FireWeakness = 1, - IceWeakness = 1, - ThunderWeakness = 1, - DarkWeakness = 1, - LightWeakness = 1, - GeneralWeakness = 1, - Experience = 1, - Prize = 1, - BonusLevel = 1 - } - }; - - using var enmpStream = new MemoryStream(); - Kh2.Battle.Enmp.Write(enmpStream, enmpEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "enmp", - Type = Bar.EntryType.List, - Stream = enmpStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "EnmpList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var serializer = new Serializer(); - var moddedEnmp = new List{ - new Kh2.Battle.Enmp - { - Id = 7, - Level = 1, - Health = new short[32], - MaxDamage = 1, - MinDamage = 1, - PhysicalWeakness = 1, - FireWeakness = 1, - IceWeakness = 1, - ThunderWeakness = 1, - DarkWeakness = 1, - LightWeakness = 1, - GeneralWeakness = 1, - Experience = 1, - Prize = 1, - BonusLevel = 1 - } - }; - writer.Write(serializer.Serialize(moddedEnmp)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var enmp = Kh2.Battle.Enmp.Read(binarc[0].Stream); - - Assert.Equal(1, enmp[0].Level); - }); - } - - [Fact] - public void ListPatchMagcTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "magc", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "MagcList.yml", - Type = "magc" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var magcEntry = new List() - { - new Kh2.Battle.Magc - { - Id = 7, - Level = 3, - World = 1, - FileName = "magic/FIRE_7.mag" - } - }; - - using var magcStream = new MemoryStream(); - Kh2.Battle.Magc.Write(magcStream, magcEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "magc", - Type = Bar.EntryType.List, - Stream = magcStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "MagcList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var serializer = new Serializer(); - var moddedMagc = new List{ - new Kh2.Battle.Magc - { - Id = 7, - Level = 3, - World = 1, - FileName = "magic/FIRE_7.mag" - } - }; - writer.Write(serializer.Serialize(moddedMagc)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var magc = Kh2.Battle.Magc.Read(binarc[0].Stream); - - Assert.Equal(3, magc[0].Level); - }); - } - - [Fact] - public void ListPatchLimtTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "Limt", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "LimtList.yml", - Type = "limt" - } - } - } - } - } - } - }; - - // Create the initial 00battle.bar file with Limt entry - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var limtEntry = new List() - { - new Kh2.Battle.Limt - { - Id = 0, - Character = Kh2.Battle.Limt.Characters.Auron, - Summon = Kh2.Battle.Limt.Characters.Sora, - Group = 0, - FileName = "auron.bar", - SpawnId = 0, - Command = 82, - Limit = 204, - World = 0, - Padding = new byte[18] - } - }; - - using var limtStream = new MemoryStream(); - Kh2.Battle.Limt.Write(limtStream, limtEntry); - limtStream.Position = 0; // Ensure stream position is reset before writing to Bar - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "Limt", - Type = Bar.EntryType.List, - Stream = limtStream - } - }); - }); - - // Create the LimtList.yml file using the serializer - File.Create(Path.Combine(ModInputDir, "LimtList.yml")).Using(stream => - { - using var writer = new StreamWriter(stream); - var moddedLimt = new List - { - new Kh2.Battle.Limt - { - Id = 0, - Character = Kh2.Battle.Limt.Characters.Auron, - Summon = Kh2.Battle.Limt.Characters.Sora, - Group = 0, - FileName = "auron.bar", - SpawnId = 0, - Command = 82, - Limit = 204, - World = 0, - Padding = new byte[18] - } - }; - writer.Write(serializer.Serialize(moddedLimt)); - writer.Flush(); - }); - - // Apply the patch - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - // Verify the output file exists - AssertFileExists(ModOutputDir, "00battle.bar"); - - // Read and validate the output file - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var limt = Kh2.Battle.Limt.Read(binarc[0].Stream); - - Assert.Equal(0, limt[0].Id); - Assert.Equal(Kh2.Battle.Limt.Characters.Auron, limt[0].Character); - Assert.Equal(Kh2.Battle.Limt.Characters.Sora, limt[0].Summon); - Assert.Equal(0, limt[0].Group); - Assert.Equal("auron.bar", limt[0].FileName.Trim()); - Assert.Equal(0u, limt[0].SpawnId); - Assert.Equal(82, limt[0].Command); - Assert.Equal(204, limt[0].Limit); - Assert.Equal(0, limt[0].World); - Assert.Equal(new byte[18], limt[0].Padding); - }); - } - - - [Fact] - public void ListPatchBtlvTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "btlv", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "BtlvList.yml", - Type = "btlv" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var btlvEntry = new List() - { - new Kh2.Battle.Btlv - { - Id = 0, - ProgressFlag = 3, - WorldZZ = 1, - Padding = new byte[5], - } - }; - - using var btlvStream = new MemoryStream(); - Kh2.Battle.Btlv.Write(btlvStream, btlvEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "btlv", - Type = Bar.EntryType.List, - Stream = btlvStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "BtlvList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var serializer = new Serializer(); - var moddedBtlv = new List{ - new Kh2.Battle.Btlv - { - Id = 0, - ProgressFlag = 3, - WorldZZ = 1, - Padding = new byte[5], - - } - }; - writer.Write(serializer.Serialize(moddedBtlv)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var btlv = Kh2.Battle.Btlv.Read(binarc[0].Stream); - - Assert.Equal(3, btlv[0].ProgressFlag); - }); - } - - [Fact] - public void ListPatchVtblTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "00battle.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "vtbl", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "VtblList.yml", - Type = "vtbl" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "00battle.bar")).Using(stream => - { - var vtblEntry = new List() - { - new Kh2.Battle.Vtbl - { - Id = 0, - CharacterId = 1, - Priority = 1, - Reserved = 0, - Voices = new List - { - new Kh2.Battle.Vtbl.Voice { VsbIndex = 0, Weight = 0 } - } - } - }; - - using var vtblStream = new MemoryStream(); - Kh2.Battle.Vtbl.Write(vtblStream, vtblEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "vtbl", - Type = Bar.EntryType.List, - Stream = vtblStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "VtblList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - var moddedVtbl = new List{ - new Kh2.Battle.Vtbl - { - Id = 0, - CharacterId = 1, - Priority = 1, - Reserved = 0, - Voices = new List - { - new Kh2.Battle.Vtbl.Voice { VsbIndex = 0, Weight = 0 } - } - } - }; - writer.Write(serializer.Serialize(moddedVtbl)); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "00battle.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "00battle.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var vtbl = Kh2.Battle.Vtbl.Read(binarc[0].Stream); - - Assert.Equal(1, vtbl[0].Priority); - }); - } - - - - [Fact] //Libretto test. - public void ListPatchLibrettoTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "libretto-ca.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "ca", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "LibrettoList.yml", - Type = "libretto" - } - } - } - } - } - } - }; - - using (var stream = File.Create(Path.Combine(AssetsInputDir, "libretto-ca.bar"))) - { - var librettoEntry = new Kh2.Libretto - { - MagicCode = 0x03, // "LIBR" in ASCII - Count = 1, - Definitions = new List - { - new Kh2.Libretto.TalkMessageDefinition - { - TalkMessageId = 1, - Type = 0, - ContentPointer = 8 + 8 // MagicCode (4 bytes) + Count (4 bytes) + Definitions (8 bytes each) - } - }, - Contents = new List> - { - new List - { - new Kh2.Libretto.TalkMessageContent { CodeType = 0x0200, Unknown = 0x0200, TextId = 2500 } - } - } - }; - - using (var librettoStream = new MemoryStream()) - { - Kh2.Libretto.Write(librettoStream, librettoEntry); - Bar.Write(stream, new Bar - { - new Bar.Entry() - { - Name = "libretto", - Type = Bar.EntryType.List, - Stream = librettoStream - } - }); - } - } - - File.Create(Path.Combine(ModInputDir, "LibrettoList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- TalkMessageId: 1"); - writer.WriteLine(" Type: 0"); - writer.WriteLine(" Contents:"); - writer.WriteLine(" - CodeType: 0x0200"); - writer.WriteLine(" Unknown: 0x0200"); - writer.WriteLine(" TextId: 2500"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "libretto-ca.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "libretto-ca.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var librettoList = Kh2.Libretto.Read(binarc[0].Stream); - var librettoEntry = librettoList.Contents[0][0]; - Assert.Equal(0x0200u, librettoEntry.CodeType); - Assert.Equal(0x0200u, librettoEntry.Unknown); - Assert.Equal(2500u, librettoEntry.TextId); - }); - } - - [Fact] - public void ListPatchLocalsetTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "07localset.bin", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "loca", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "LocalsetList.yml", - Type = "localset" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "07localset.bin")).Using(stream => - { - var localEntry = new List() - { - new Kh2.Localset - { - ProgramId = 1300, - MapNumber = 6, - } - }; - - using var localStream = new MemoryStream(); - Kh2.Localset.Write(localStream, localEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "loca", - Type = Bar.EntryType.List, - Stream = localStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "LocalsetList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- ProgramId: 1300"); - writer.WriteLine(" MapNumber: 6"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "07localset.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "07localset.bin")).Using(stream => - { - var binarc = Bar.Read(stream); - var localStream = Kh2.Localset.Read(binarc[0].Stream); - Assert.Equal(1300u, localStream[0].ProgramId); - Assert.Equal(6u, localStream[0].MapNumber); - }); - } - - [Fact] - public void ListPatchJigsawTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "15jigsaw.bin", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "JigsawList.yml", - Type = "jigsaw", - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "15jigsaw.bin")).Using(stream => - { - var jigsawEntry = new List() - { - new Kh2.Jigsaw - { - Picture = Kh2.Jigsaw.PictureName.Duality, - Part = 2, - Text = 1500 - } - }; - Kh2.Jigsaw.Write(stream, jigsawEntry); - }); - - File.Create(Path.Combine(ModInputDir, "JigsawList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Picture: Duality"); - writer.WriteLine(" Part: 2"); - writer.WriteLine(" Text: 1500"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "15jigsaw.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "15jigsaw.bin")).Using(stream => - { - var jigsawStream = Kh2.Jigsaw.Read(stream); - Assert.Equal(2, jigsawStream[0].Part); - }); - - } - - [Fact] - public void ListPatchSlctTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "14mission.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "slct", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "SlctList.yml", - Type = "slct" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "14mission.bar")).Using(stream => - { - var slctEntry = new List() - { - new Kh2.Slct - { - Id = 1, - ChoiceNum = 2, - ChoiceDefault = 3, - Choice = Enumerable.Range(0, 4).Select(_ => new Kh2.ChoiceEntry { Id = 0, MessageId = 0 }).ToArray(), - Padding = new byte[25] - } - }; - using var slctStream = new MemoryStream(); - Kh2.Slct.Write(slctStream, slctEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "slct", - Type = Bar.EntryType.List, - Stream = slctStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "SlctList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Id: 1"); - writer.WriteLine(" ChoiceNum: 2"); - writer.WriteLine(" ChoiceDefault: 3"); - writer.WriteLine(" Choice:"); - writer.WriteLine(" - Id: 0"); - writer.WriteLine(" MessageId: 0"); - writer.WriteLine(" Padding:"); - writer.WriteLine(" - 0"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "14mission.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "14mission.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var slctStream = Kh2.Slct.Read(binarc[0].Stream); - Assert.Equal(1, slctStream[0].Id); - Assert.Equal(2, slctStream[0].ChoiceNum); - Assert.Equal(3, slctStream[0].ChoiceDefault); - }); - } - - [Fact] - public void ListPatchWentTest() - { - var patcher = new PatcherProcessor(); - - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bin", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "went", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "WentList.yml", - Type = "went" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bin")).Using(stream => - { - var went = new Kh2.SystemData.Went - { - Offsets = new List(new uint[70]), - Sets = new List() - }; - - var set = new Kh2.SystemData.Went.WentSet() - { - OriginalOffset = 1, - WeaponIds = new List() { 100 } - }; - - went.Sets.Add(set); - - went.Offsets[1] = 1; - - using var wentStream = new MemoryStream(); - went.Write(wentStream); - - Bar.Write(stream, new Bar() - { - new Bar.Entry() - { - Name = "went", - Type = Bar.EntryType.List, - Stream = wentStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "WentList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - - writer.WriteLine("Sora:"); - writer.WriteLine(" 0: 500"); - writer.WriteLine(" 1: 777"); - - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "03system.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bin")).Using(stream => - { - var binarc = Bar.Read(stream); - var went = Kh2.SystemData.Went.Read(binarc[0].Stream); - - uint soraOffset = went.Offsets[1]; - - var set = went.Sets.Find(x => x.OriginalOffset == soraOffset); - - Assert.Equal(2, set.WeaponIds.Count); - Assert.Equal((uint)500, set.WeaponIds[0]); - Assert.Equal((uint)777, set.WeaponIds[1]); - }); - } - - [Fact] - public void ListPatchSstmTest() - { - var patcher = new PatcherProcessor(); - - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bin", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "pref", - Method = "binarc", - Type = "Binary", - Source = new List() - { - new AssetFile() - { - Name = "sstm", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "SstmList.yml", - Type = "sstm" - } - } - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bin")).Using(stream => - { - var sstm = new Kh2.SystemData.Sstm() - { - DriveTime = 10.0f, - AntiFormDriveCount = 5 - }; - - using var sstmStream = new MemoryStream(); - sstm.Write(sstmStream); - - using var prefStream = new MemoryStream(); - Bar.Write(prefStream, new Bar() - { - new Bar.Entry() - { - Name = "sstm", - Type = Bar.EntryType.List, - Stream = sstmStream - } - }); - - Bar.Write(stream, new Bar() - { - new Bar.Entry() - { - Name = "pref", - Type = Bar.EntryType.Binary, - Stream = prefStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "SstmList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("DriveTime: 123.5"); - writer.WriteLine("AntiFormDriveCount: 99"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bin")).Using(stream => - { - var systemBar = Bar.Read(stream); - var prefBar = Bar.Read(systemBar[0].Stream); - - var sstm = Kh2.SystemData.Sstm.Read(prefBar[0].Stream); - - Assert.Equal(123.5f, sstm.DriveTime); - Assert.Equal(99, sstm.AntiFormDriveCount); - }); - } - - [Fact] - public void ListPatchPrtyTest() - { - var patcher = new PatcherProcessor(); - - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "03system.bin", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "pref", - Method = "binarc", - Type = "Binary", - Source = new List() - { - new AssetFile() - { - Name = "prty", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "PrtyList.yml", - Type = "prty" - } - } - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "03system.bin")).Using(stream => - { - const int count = 70; - - var sharedEntry = new Kh2.SystemData.Prty() - { - WalkSpeed = 1.0f, - RunSpeed = 2.0f - }; - - var prtyFile = new Kh2.SystemData.PrtyFile() - { - Count = count, - Offsets = new int[count], - UniqueEntries = new Dictionary() - }; - - using var tempStream = new MemoryStream(); - - prtyFile.Write(tempStream); - - int headerSize = 4 + (count * 4); - int entryOffset = headerSize; - - for (int i = 0; i < count; i++) - prtyFile.Offsets[i] = (i == 0) ? 0 : entryOffset; - - prtyFile.UniqueEntries[entryOffset] = sharedEntry; - - using var prtyStream = new MemoryStream(); - prtyFile.Write(prtyStream); - - using var prefStream = new MemoryStream(); - Bar.Write(prefStream, new Bar() - { - new Bar.Entry() - { - Name = "prty", - Type = Bar.EntryType.List, - Stream = prtyStream - } - }); - - Bar.Write(stream, new Bar() - { - new Bar.Entry() - { - Name = "pref", - Type = Bar.EntryType.Binary, - Stream = prefStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "PrtyList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("Sora:"); - writer.WriteLine(" WalkSpeed: 5.5"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - File.OpenRead(Path.Combine(ModOutputDir, "03system.bin")).Using(stream => - { - var systemBar = Bar.Read(stream); - var prefBar = Bar.Read(systemBar[0].Stream); - - var prtyFile = Kh2.SystemData.PrtyFile.Read(prefBar[0].Stream); - - int realIndex = Kh2.SystemData.Prty.CharacterMap["Sora"] + 1; - int offset = prtyFile.Offsets[realIndex]; - - var entry = prtyFile.UniqueEntries[offset]; - - Assert.Equal(5.5f, entry.WalkSpeed); - }); - } - - - [Fact] - public void ListPatchPlacesTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "place.bin", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "PlaceList.yml", - Type = "place", - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "place.bin")).Using(stream => - { - var placeEntry = new List() - { - new Kh2.Places - { - MessageId = 100, - Padding = 0, - } - }; - Kh2.Places.Write(stream, placeEntry); - }); - - File.Create(Path.Combine(ModInputDir, "PlaceList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- MessageId: 100"); - writer.WriteLine(" Padding: 0"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "place.bin"); - - File.OpenRead(Path.Combine(ModOutputDir, "place.bin")).Using(stream => - { - var placesStream = Kh2.Places.Read(stream); - Assert.Equal(100, placesStream[0].MessageId); - }); - - } - - [Fact] - public void ListPatchSoundInfoTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "12soundinfo.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "zz", - Method = "listpatch", - Type = "List", - Source = new List() - { - new AssetFile() - { - Name = "SoundInfoList.yml", - Type = "soundinfo" - } - } - } - } - } - } - }; - File.Create(Path.Combine(AssetsInputDir, "12soundinfo.bar")).Using(stream => - { - var soundinfoEntry = new List() - { - new Kh2.Soundinfo - { - Reverb = -1, - Rate = 1, - } - }; - Kh2.Soundinfo.Write(stream, soundinfoEntry); - }); - - File.Create(Path.Combine(ModInputDir, "SoundInfoList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Reverb: -1"); - writer.WriteLine(" Rate: 1"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "12soundinfo.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "12soundinfo.bar")).Using(stream => - { - var soundinfoStream = Kh2.Soundinfo.Read(stream); - Assert.Equal(1, soundinfoStream[0].Rate); - }); - - } - - [Fact] - public void ListPatchMixdataReciTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "mixdata.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "reci", - Method = "synthpatch", - Type = "Synthesis", - Source = new List() - { - new AssetFile() - { - Name = "ReciList.yml", - Type = "recipe" - } - } - } - } - } - } - }; - - File.Create(Path.Combine(AssetsInputDir, "mixdata.bar")).Using(stream => - { - var recipeEntry = new List() - { - new Kh2.Mixdata.ReciLP - { - Id = 1, - Unlock = 0, - Rank = 0, - } - }; - using var recipeStream = new MemoryStream(); - Kh2.Mixdata.ReciLP.Write(recipeStream, recipeEntry); - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "reci", - Type = Bar.EntryType.List, - Stream = recipeStream - } - }); - }); - - File.Create(Path.Combine(ModInputDir, "ReciList.yml")).Using(stream => - { - var writer = new StreamWriter(stream); - writer.WriteLine("- Id: 1"); - writer.WriteLine(" Rank: 0"); - writer.Flush(); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, "mixdata.bar"); - - File.OpenRead(Path.Combine(ModOutputDir, "mixdata.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var recipeStream = Kh2.Mixdata.ReciLP.Read(binarc[0].Stream); - Assert.Equal(1, recipeStream[0].Id); - Assert.Equal(0, recipeStream[0].Rank); - }); - - } - - [Fact] - public void ListPatchMixdataLeveLPTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "mixdata.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "leve", - Method = "synthpatch", - Type = "Synthesis", - Source = new List() - { - new AssetFile() - { - Name = "LeveList.yml", - Type = "level" - } - } - } - } - } - } - }; - - // Create the initial mixdata.bar file with LeveLP entry - File.Create(Path.Combine(AssetsInputDir, "mixdata.bar")).Using(stream => - { - var leveEntry = new List() - { - new Kh2.Mixdata.LeveLP - { - Title = 1, - Stat = 2, - Enable = 1, - Padding = 0, - Exp = 100 - } - }; - - using var leveStream = new MemoryStream(); - Kh2.Mixdata.LeveLP.Write(leveStream, leveEntry); - leveStream.Position = 0; // Ensure stream position is reset before writing to Bar - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "leve", - Type = Bar.EntryType.List, - Stream = leveStream - } - }); - }); - - // Create the LeveList.yml file using the serializer - File.Create(Path.Combine(ModInputDir, "LeveList.yml")).Using(stream => - { - using var writer = new StreamWriter(stream); - var moddedLeve = new List - { - new Kh2.Mixdata.LeveLP - { - Title = 1, - Stat = 2, - Enable = 1, - Padding = 0, - Exp = 100 - } - }; - writer.Write(serializer.Serialize(moddedLeve)); - writer.Flush(); - }); - - // Apply the patch - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - // Verify the output file exists - AssertFileExists(ModOutputDir, "mixdata.bar"); - - // Read and validate the output file - File.OpenRead(Path.Combine(ModOutputDir, "mixdata.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var leveStream = Kh2.Mixdata.LeveLP.Read(binarc[0].Stream); - - Assert.Equal(1, leveStream[0].Title); - Assert.Equal(2, leveStream[0].Stat); - Assert.Equal(1, leveStream[0].Enable); - Assert.Equal(0, leveStream[0].Padding); - Assert.Equal(100, leveStream[0].Exp); - }); - } - - [Fact] - public void ListPatchMixdataCondLPTest() - { - var patcher = new PatcherProcessor(); - var serializer = new Serializer(); - var patch = new Metadata() - { - Assets = new List() - { - new AssetFile() - { - Name = "mixdata.bar", - Method = "binarc", - Source = new List() - { - new AssetFile() - { - Name = "cond", - Method = "synthpatch", - Type = "Synthesis", - Source = new List() - { - new AssetFile() - { - Name = "CondList.yml", - Type = "condition" - } - } - } - } - } - } - }; - - // Create the initial mixdata.bar file with CondLP entry - File.Create(Path.Combine(AssetsInputDir, "mixdata.bar")).Using(stream => - { - var condEntry = new List() - { - new Kh2.Mixdata.CondLP - { - TextId = 1, - Reward = 100, - Type = Kh2.Mixdata.CondLP.RewardType.Item, - MaterialType = 0, - MaterialRank = 1, - ItemCollect = Kh2.Mixdata.CondLP.CollectionType.Stack, - Count = 10, - ShopUnlock = 5 - } - }; - - using var condStream = new MemoryStream(); - Kh2.Mixdata.CondLP.Write(condStream, condEntry); - condStream.Position = 0; // Ensure stream position is reset before writing to Bar - Bar.Write(stream, new Bar() { - new Bar.Entry() - { - Name = "cond", - Type = Bar.EntryType.List, - Stream = condStream - } - }); - }); - - // Create the CondList.yml file using the serializer - File.Create(Path.Combine(ModInputDir, "CondList.yml")).Using(stream => - { - using var writer = new StreamWriter(stream); - var moddedCond = new List - { - new Kh2.Mixdata.CondLP - { - TextId = 1, - Reward = 100, - Type = Kh2.Mixdata.CondLP.RewardType.Item, - MaterialType = 0, - MaterialRank = 1, - ItemCollect = Kh2.Mixdata.CondLP.CollectionType.Stack, - Count = 10, - ShopUnlock = 5 - } - }; - writer.Write(serializer.Serialize(moddedCond)); - writer.Flush(); - }); - - // Apply the patch - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - // Verify the output file exists - AssertFileExists(ModOutputDir, "mixdata.bar"); - - // Read and validate the output file - File.OpenRead(Path.Combine(ModOutputDir, "mixdata.bar")).Using(stream => - { - var binarc = Bar.Read(stream); - var condStream = Kh2.Mixdata.CondLP.Read(binarc[0].Stream); - - Assert.Equal(1, condStream[0].TextId); - Assert.Equal(100, condStream[0].Reward); - Assert.Equal(Kh2.Mixdata.CondLP.RewardType.Item, condStream[0].Type); - Assert.Equal(0, condStream[0].MaterialType); - Assert.Equal(1, condStream[0].MaterialRank); - Assert.Equal(Kh2.Mixdata.CondLP.CollectionType.Stack, condStream[0].ItemCollect); - Assert.Equal(10, condStream[0].Count); - Assert.Equal(5, condStream[0].ShopUnlock); - }); - } - - - [Fact] - public void BbsArcCreateArcTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List { - new AssetFile - { - Name = "somedir/somearc.arc", - Method = "bbsarc", - Source = new List { - new AssetFile - { - Name = "newfile", - Method = "copy", - Source = new List { - new AssetFile - { - Name = "somedir/somearc/newfile.bin" - } - } - } - } - } - } - }; - - CreateFile(ModInputDir, "somedir/somearc/newfile.bin").Using(x => - { - x.Write(new byte[] { 4, 5, 6, 7 }); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertArcFile("newfile", entry => - { - Assert.Equal(4, entry.Data.Length); - Assert.Equal(new byte[] { 4, 5, 6, 7 }, entry.Data); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void BbsArcAddToArcTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List { - new AssetFile - { - Name = "somedir/somearc.arc", - Method = "bbsarc", - Source = new List { - new AssetFile - { - Name = "newfile", - Method = "copy", - Source = new List { - new AssetFile - { - Name = "somedir/somearc/newfile.bin" - } - } - } - } - } - } - }; - - CreateFile(AssetsInputDir, "somedir/somearc.arc").Using(x => - { - Arc.Write(new List - { - new Arc.Entry - { - Name = "abcd", - Data = new byte[] {0, 1, 2, 3 } - } - }, x); - }); - - CreateFile(ModInputDir, "somedir/somearc/newfile.bin").Using(x => - { - x.Write(new byte[] { 4, 5, 6, 7 }); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertArcFile("abcd", entry => - { - Assert.Equal(4, entry.Data.Length); - Assert.Equal(new byte[] { 0, 1, 2, 3 }, entry.Data); - }, ModOutputDir, patch.Assets[0].Name); - AssertArcFile("newfile", entry => - { - Assert.Equal(4, entry.Data.Length); - Assert.Equal(new byte[] { 4, 5, 6, 7 }, entry.Data); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void BbsArcReplaceInArcTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List { - new AssetFile - { - Name = "somedir/somearc.arc", - Method = "bbsarc", - Source = new List { - new AssetFile - { - Name = "abcd", - Method = "copy", - Source = new List { - new AssetFile - { - Name = "somedir/somearc/abcd.bin" - } - } - } - } - } - } - }; - - CreateFile(AssetsInputDir, "somedir/somearc.arc").Using(x => - { - Arc.Write(new List - { - new Arc.Entry - { - Name = "abcd", - Data = new byte[] {0, 1, 2, 3} - } - }, x); - }); - - CreateFile(ModInputDir, "somedir/somearc/abcd.bin").Using(x => - { - x.Write(new byte[] { 4, 5, 6, 7 }); - }); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertArcFile("abcd", entry => - { - Assert.Equal(4, entry.Data.Length); - Assert.Equal(new byte[] { 4, 5, 6, 7 }, entry.Data); - }, ModOutputDir, patch.Assets[0].Name); - } - - [Fact] - public void ProcessMultipleTest() - { - var patcher = new PatcherProcessor(); - var patch = new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "somedir/somefile.bar", - Method = "binarc", - Multi = new List - { - new Multi { Name = "somedir/another.bar" } - }, - Source = new List - { - new AssetFile - { - Name = "test", - Method = "imgd", - Type = "imgd", - Source = new List - { - new AssetFile - { - Name = "sample.png", - IsSwizzled = false - } - } - } - } - } - } - }; - - File.Copy("Imaging/res/png/32.png", Path.Combine(ModInputDir, "sample.png")); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertFileExists(ModOutputDir, patch.Assets[0].Name); - AssertBarFile("test", entry => - { - Assert.True(Imgd.IsValid(entry.Stream)); - }, ModOutputDir, patch.Assets[0].Name); - - AssertFileExists(ModOutputDir, patch.Assets[0].Multi[0].Name); - AssertBarFile("test", entry => - { - Assert.True(Imgd.IsValid(entry.Stream)); - }, ModOutputDir, patch.Assets[0].Multi[0].Name); - } - - - [Fact] - public void Kh1ArdResourceReplaceTest() - { - var patcher = new PatcherProcessor(); - var patch = Kh1ArdPatch(("1", "xa_al_9999.mset"), ("2", "tw_6100.moa")); - - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "xa_ex_0010.mdls", "xa_ex_0010.mset", "ex_6540.moa", "ex_6540.moa.mset"))); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertArdResources(new[] - { - "xa_ex_0010.mdls", "xa_al_9999.mset", "tw_6100.moa", "ex_6540.moa.mset" - }, ModOutputDir, "tw01.ard"); - } - - [Fact] - public void Kh1ArdResourceReadsTheReplacementsFromItsSourceFileTest() - { - var yml = - "title: source file test\n" + - "assets:\n" + - "- name: tw01.ard\n" + - " method: kh1ardresource\n" + - " source:\n" + - " - name: files/tw01.yml\n"; - - var patch = new MemoryStream(Encoding.UTF8.GetBytes(yml)).Using(Metadata.Read); - - CreateFile(ModInputDir, "files/tw01.yml") - .Using(x => x.Write(Encoding.UTF8.GetBytes("1: xa_al_9999.mset\n"))); - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "a.mdls", "a.mset", "b.moa", "b.moa.mset"))); - - new PatcherProcessor().Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertArdResources(new[] { "a.mdls", "xa_al_9999.mset", "b.moa", "b.moa.mset" }, - ModOutputDir, "tw01.ard"); - } - - [Fact] - public void Kh1ArdResourceReplaceOfReplacedFileTest() - { - var patcher = new PatcherProcessor(); - var patch = Kh1ArdPatch(("1", "xa_al_9999.mset")); - - // The vanilla file the patch must NOT be applied to. - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "vanilla_a.mdls", "vanilla_a.mset", "vanilla_b.moa", "vanilla_b.moa.mset"))); - - // A higher ranked mod already staged its own replacement of the same file. - CreateFile(ModOutputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "replaced_a.mdls", "replaced_a.mset", "replaced_b.moa", "replaced_b.moa.mset"))); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - AssertArdResources(new[] - { - "replaced_a.mdls", "xa_al_9999.mset", "replaced_b.moa", "replaced_b.moa.mset" - }, ModOutputDir, "tw01.ard"); - } - - [Fact] - public void Kh1ArdResourceReplacePreservesTheRestOfTheFileTest() - { - var patcher = new PatcherProcessor(); - var patch = Kh1ArdPatch(("0", "c.mdls")); - - var original = CreateArd("a.mdls", "a.mset", "b.moa", "b.moa.mset"); - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(original)); - - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true); - - var patched = File.ReadAllBytes(Path.Combine(ModOutputDir, "tw01.ard")); - Assert.Equal(original.Length, patched.Length); - // The header and everything past the resource list must be byte identical. - Assert.Equal(original.Take(ArdResourceListOffset), patched.Take(ArdResourceListOffset)); - Assert.Equal(original.Skip(ArdResourceListEnd), patched.Skip(ArdResourceListEnd)); - } - - [Fact] - public void Kh1ArdResourceReplaceOutOfRangeThrowsTest() - { - var patcher = new PatcherProcessor(); - var patch = Kh1ArdPatch(("9", "nope.mdls")); - - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "a.mdls", "a.mset", "b.moa", "b.moa.mset"))); - - Assert.Throws(() => - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true)); - } - - [Fact] - public void Kh1ArdResourceReplaceEmptyNameThrowsTest() - { - var patcher = new PatcherProcessor(); - var patch = Kh1ArdPatch(("0", "")); - - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "a.mdls", "a.mset", "b.moa", "b.moa.mset"))); - - Assert.Throws(() => - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true)); - } - - [Fact] - public void Kh1ArdResourceReplaceNameTooLongThrowsTest() - { - var patcher = new PatcherProcessor(); - var patch = Kh1ArdPatch(("0", new string('x', OpenKh.Kh1.Ard.MaxNameLength + 1))); - - CreateFile(AssetsInputDir, "tw01.ard").Using(x => x.Write(CreateArd( - "a.mdls", "a.mset", "b.moa", "b.moa.mset"))); - - Assert.Throws(() => - patcher.Patch(AssetsInputDir, ModOutputDir, patch, ModInputDir, Tests: true)); - } - - private const int ArdHeaderSize = 4 + (32 + 1) * 4; - private const int ArdResourceListOffset = 0x100; - - private static int ArdResourceListEnd => ArdResourceListOffset + 4 * OpenKh.Kh1.Ard.NameSize; - - private static Metadata Kh1ArdPatch(params (string Index, string Name)[] replacements) - { - var lines = replacements.Select(x => $"{x.Index}: {x.Name}"); - File.WriteAllText(Path.Combine(ModInputDir, "tw01.yml"), - string.Join(Environment.NewLine, lines) + Environment.NewLine); - - return new Metadata - { - Assets = new List - { - new AssetFile - { - Name = "tw01.ard", - Method = "kh1ardresource", - Source = new List { new AssetFile { Name = "tw01.yml" } } - } - } - }; - } - - /// - /// Builds a minimal but structurally valid .ard: 32 entries, with entry 5 holding - /// the given names and a marker block after it to catch collateral damage. - /// - private static byte[] CreateArd(params string[] names) - { - var listEnd = ArdResourceListOffset + names.Length * OpenKh.Kh1.Ard.NameSize; - var length = listEnd + 0x80; - var data = new byte[length]; - - BitConverter.GetBytes(32).CopyTo(data, 0); - for (var i = 0; i <= 32; i++) - { - var offset = i <= 5 ? ArdResourceListOffset : i == 6 ? listEnd : length; - BitConverter.GetBytes(offset).CopyTo(data, 4 + i * 4); - } - - for (var i = 0; i < names.Length; i++) - Encoding.ASCII.GetBytes(names[i]).CopyTo(data, ArdResourceListOffset + i * OpenKh.Kh1.Ard.NameSize); - - for (var i = listEnd; i < length; i++) - data[i] = 0xCD; - - Assert.True(ArdHeaderSize <= ArdResourceListOffset); - return data; - } - - private static void AssertArdResources(string[] expected, params string[] paths) => - File.OpenRead(Path.Join(paths)).Using(x => - Assert.Equal(expected, OpenKh.Kh1.Ard.ReadResourceList(x))); - - private static void AssertFileExists(params string[] paths) - { - var filePath = Path.Join(paths); - if (File.Exists(filePath) == false) - Assert.Fail($"File not found '{filePath}'"); - } - - private static void AssertBarFile(string name, Action assertion, params string[] paths) - { - var filePath = Path.Join(paths); - var entries = File.OpenRead(filePath).Using(x => - { - if (!Bar.IsValid(x)) - Assert.Fail($"Not a valid BinArc"); - return Bar.Read(x); - }); - - var entry = entries.SingleOrDefault(x => x.Name == name); - if (entry == null) - throw new XunitException($"Entry '{name}' not found"); - - assertion(entry); - } - - private static void AssertArcFile(string name, Action assertion, params string[] paths) - { - var filePath = Path.Join(paths); - var entries = File.OpenRead(filePath).Using(x => - { - if (!Arc.IsValid(x)) - Assert.Fail($"Not a valid Arc"); - return Arc.Read(x); - }); - - var entry = entries.SingleOrDefault(x => x.Name == name); - if (entry == null) - throw new XunitException($"Arc Entry '{name}' not found"); - - assertion(entry); - } - - private static Stream CreateFile(params string[] paths) - { - var filePath = Path.Join(paths); - var dirPath = Path.GetDirectoryName(filePath); - Directory.CreateDirectory(dirPath); - return File.Create(filePath); - } - } + public class PatcherTests + { } } diff --git a/OpenKh.Tools.Kh2ObjectEditor/Modules/AI/ModuleAI_VM.cs b/OpenKh.Tools.Kh2ObjectEditor/Modules/AI/ModuleAI_VM.cs index 09a39a14d..1a5305550 100644 --- a/OpenKh.Tools.Kh2ObjectEditor/Modules/AI/ModuleAI_VM.cs +++ b/OpenKh.Tools.Kh2ObjectEditor/Modules/AI/ModuleAI_VM.cs @@ -1,6 +1,6 @@ -using OpenKh.Command.Bdxio.Models; -using OpenKh.Command.Bdxio.Utils; using OpenKh.Kh2; +using OpenKh.Kh2.Bdx.Models; +using OpenKh.Kh2.Bdx.Utils; using OpenKh.Tools.Kh2ObjectEditor.Services; using OpenKh.Tools.Kh2ObjectEditor.Utils; using System; diff --git a/OpenKh.Tools.Kh2ObjectEditor/OpenKh.Tools.Kh2ObjectEditor.csproj b/OpenKh.Tools.Kh2ObjectEditor/OpenKh.Tools.Kh2ObjectEditor.csproj index b38214c40..930f81bd6 100644 --- a/OpenKh.Tools.Kh2ObjectEditor/OpenKh.Tools.Kh2ObjectEditor.csproj +++ b/OpenKh.Tools.Kh2ObjectEditor/OpenKh.Tools.Kh2ObjectEditor.csproj @@ -19,7 +19,6 @@ - diff --git a/OpenKh.Tools.ModManager/App.axaml b/OpenKh.Tools.ModManager/App.axaml new file mode 100644 index 000000000..bbfe7c301 --- /dev/null +++ b/OpenKh.Tools.ModManager/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/OpenKh.Tools.ModManager/App.axaml.cs b/OpenKh.Tools.ModManager/App.axaml.cs new file mode 100644 index 000000000..55d7222da --- /dev/null +++ b/OpenKh.Tools.ModManager/App.axaml.cs @@ -0,0 +1,31 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using OpenKh.Tools.ModManager.Services; +using OpenKh.Tools.ModManager.ViewModels; +using OpenKh.Tools.ModManager.Views; +using SharpYaml; +using System.IO; + +namespace OpenKh.Tools.ModManager; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainView + { + DataContext = new MainViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/OpenKh.Tools.ModManager/Assets/avalonia-logo.ico b/OpenKh.Tools.ModManager/Assets/avalonia-logo.ico new file mode 100644 index 000000000..f7da8bb58 Binary files /dev/null and b/OpenKh.Tools.ModManager/Assets/avalonia-logo.ico differ diff --git a/OpenKh.Tools.ModManager/Assets/invalid_mod.png b/OpenKh.Tools.ModManager/Assets/invalid_mod.png new file mode 100644 index 000000000..06f4fbd0f Binary files /dev/null and b/OpenKh.Tools.ModManager/Assets/invalid_mod.png differ diff --git a/OpenKh.Tools.ModManager/Classes/Config.cs b/OpenKh.Tools.ModManager/Classes/Config.cs new file mode 100644 index 000000000..f8aa22c51 --- /dev/null +++ b/OpenKh.Tools.ModManager/Classes/Config.cs @@ -0,0 +1,173 @@ +using OpenKh.Tools.ModManager.Services; +using SharpYaml; +using SharpYaml.Model; +using SharpYaml.Serialization; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.RegularExpressions; + +namespace OpenKh.Tools.ModManager.Classes +{ + public enum Platform : int + { + PCSX2, + STEAM, + EPIC_GAMES_STORE + }; + + public enum BuildType : int + { + PATCH, + PANACEA + }; + + public enum Game : int + { + KINGDOM_HEARTS, + KINGDOM_HEARTS_II, + CHAIN_OF_MEMORIES, + BIRTH_BY_SLEEP, + DREAM_DROP_DISTANCE + }; + + // Frontend Configuration + public class Frontend + { + public Platform TargetPlatform { get; set; } + + public Game TargetGame { get; set; } + + public BuildType ModBuildType { get; set; } + + public string? LaunchArguments { get; set; } + + public string? ModPath { get; set; } + + public string? BuildPath { get; set; } + + public string[]? TargetPreset { get; set; } + + public string? PresetPath { get; set; } + + public bool UpdateMods { get; set; } + + public string? DataPath { get; set; } + + public string[]? GamePath { get; set; } + } + + // Panacea Configuration + public class Panacea + { + public bool IsConsole { get; set; } + + public bool IsDebug { get; set; } + + public bool IsSoundDebug { get; set; } + + public bool IsCacheActive { get; set; } + } + + // PCSX2 Configuration + public class Emulator + { + public string[]? EmuPath { get; set; } + + public string[]? RomPath { get; set; } + } + + public class Config + { + public static Dictionary GameExecutable = new Dictionary() + { + { Game.KINGDOM_HEARTS, "KINGDOM HEARTS FINAL MIX.exe" }, + { Game.KINGDOM_HEARTS_II, "KINGDOM HEARTS II FINAL MIX.exe" }, + { Game.CHAIN_OF_MEMORIES, "KINGDOM HEARTS Re_Chain of Memories.exe" }, + { Game.BIRTH_BY_SLEEP, "KINGDOM HEARTS Birth by Sleep FINAL MIX.exe" }, + { Game.DREAM_DROP_DISTANCE, "KINGDOM HEARTS Dream Drop Distance.exe" }, + }; + + public static Dictionary GameShorthand = new Dictionary() + { + { Game.KINGDOM_HEARTS, "kh1" }, + { Game.KINGDOM_HEARTS_II, "kh2" }, + { Game.CHAIN_OF_MEMORIES, "Recom" }, + { Game.BIRTH_BY_SLEEP, "bbs" }, + { Game.DREAM_DROP_DISTANCE, "kh3d" }, + }; + + public Frontend Frontend { get; set; } + public Panacea Panacea { get; set; } + public Emulator Emulator { get; set; } + + public static Config Load() + { + var _fetchConfigFile = System.IO.Path.Combine(AppContext.BaseDirectory, "config.yml"); + var _fetchConfigRAW = File.ReadAllText(_fetchConfigFile); + + return YamlSerializer.Deserialize(_fetchConfigRAW); + } + + public bool IsValid() + { + if (Frontend.TargetPlatform != Platform.PCSX2) + { + var _fetchTargetGame = Frontend.TargetGame; + + // Check if the game is Dream Drop Distance and the second Game Path has been declared. + // Otherwise, check if the game is NOT Dream Drop Distance. + // If neither of these are true, the config isn't valid. + + var _isDDDConfigValid = _fetchTargetGame != Game.DREAM_DROP_DISTANCE || (_fetchTargetGame == Game.DREAM_DROP_DISTANCE && Frontend.GamePath.Length == 2 && !String.IsNullOrEmpty(Frontend.GamePath[1])); + + if (!_isDDDConfigValid) + return false; + + else + { + // Fetch the second Game Path if the game is Dream Drop Distance, fetch the first one otherwise. + var _fetchGamePath = _fetchTargetGame == Game.DREAM_DROP_DISTANCE ? PathService.ResolvePath28(this) : PathService.ResolvePath1525(this); + + if (String.IsNullOrEmpty(_fetchGamePath)) + return false; + + else + { + // Construct the paths for the game executable and Panacea. + var _fetchExePath = System.IO.Path.Combine(_fetchGamePath, Config.GameExecutable[Frontend.TargetGame]); + var _fetchSettingsPath = System.IO.Path.Combine(_fetchGamePath, "panacea_settings.txt"); + + // Verify the game executable and directory exists as configured. If the build type is PANACEA, also verify Panacea's existence. + var _isGameConfigValid = Directory.Exists(_fetchGamePath) && File.Exists(_fetchExePath); + var _isPanaceaConfigValid = (Frontend.ModBuildType == BuildType.PANACEA && File.Exists(_fetchSettingsPath)) || Frontend.ModBuildType == BuildType.PATCH; + + if (_isPanaceaConfigValid && Frontend.ModBuildType == BuildType.PANACEA) + _isPanaceaConfigValid = PackageService.EnsurePanacea(this); + + // If either are not valid, mark the config as faulty. + if (!_isGameConfigValid || !_isPanaceaConfigValid) + return false; + + else + return true; + } + } + } + + else + return true; + } + + public void Commit() + { + var _fetchConfigFile = System.IO.Path.Combine(AppContext.BaseDirectory, "config.yml"); + var _fetchSerialize = YamlSerializer.Serialize(this); + + File.WriteAllText(_fetchConfigFile, _fetchSerialize); + } + } +} diff --git a/OpenKh.Tools.ModManager/Classes/MIPS.cs b/OpenKh.Tools.ModManager/Classes/MIPS.cs new file mode 100644 index 000000000..86e9eb438 --- /dev/null +++ b/OpenKh.Tools.ModManager/Classes/MIPS.cs @@ -0,0 +1,260 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.ModManager.Classes +{ + public static class MIPS + { + // Converted from https://github.com/Xeeynamo/mipsdump/blob/master/mipsdump/Instructions.fs + + public const uint Zero = 0x00; + public const uint AT = 0x01; + public const uint V0 = 0x02; + public const uint V1 = 0x03; + public const uint A0 = 0x04; + public const uint A1 = 0x05; + public const uint A2 = 0x06; + public const uint A3 = 0x07; + public const uint T0 = 0x08; + public const uint T1 = 0x09; + public const uint T2 = 0x0A; + public const uint T3 = 0x0B; + public const uint T4 = 0x0C; + public const uint T5 = 0x0D; + public const uint T6 = 0x0E; + public const uint T7 = 0x0F; + public const uint S0 = 0x10; + public const uint S1 = 0x11; + public const uint S2 = 0x12; + public const uint S3 = 0x13; + public const uint S4 = 0x14; + public const uint S5 = 0x15; + public const uint S6 = 0x16; + public const uint S7 = 0x17; + public const uint T8 = 0x18; + public const uint T9 = 0x19; + public const uint K0 = 0x1A; + public const uint K1 = 0x1B; + public const uint GP = 0x1C; + public const uint SP = 0x1D; + public const uint FP = 0x1E; + public const uint RA = 0x1F; + + public enum Regimm + { + BLTZ = 0x00, + BGEZ = 0x01, + BLTZAL = 0x10, + BGEZAL = 0x11, + } + + public enum Op + { + SPECIAL = 0x00, + REGIMM = 0x01, + J = 0x02, + JAL = 0x03, + BEQ = 0x04, + BNE = 0x05, + BLEZ = 0x06, + BGTZ = 0x07, + ADDI = 0x08, + ADDIU = 0x09, + SLTI = 0x0A, + SLTIU = 0x0B, + ANDI = 0x0C, + ORI = 0x0D, + XORI = 0x0E, + LUI = 0x0F, + C0 = 0x10, + C1 = 0x11, + C2 = 0x12, + C3 = 0x13, + LB = 0x20, + LH = 0x21, + LWL = 0x22, + LW = 0x23, + LBU = 0x24, + LHU = 0x25, + LWR = 0x26, + SB = 0x28, + SH = 0x29, + SWL = 0x2a, + SW = 0x2b, + SWR = 0x2e, + LWC0 = 0x30, + LWC1 = 0x31, + LWC2 = 0x32, + LWC3 = 0x33, + LD = 0x37, + SWC0 = 0x38, + SWC1 = 0x39, + SWC2 = 0x3a, + SWC3 = 0x3b, + SD = 0x3f, + } + + public enum Special + { + SLL = 0x00, + SRL = 0x02, + SRA = 0x03, + SLLV = 0x04, + SRLV = 0x06, + SRAV = 0x07, + JR = 0x08, + JALR = 0x09, + SYSCALL = 0x0C, + BREAK = 0x0D, + MFHI = 0x10, + MTHI = 0x11, + MFLO = 0x12, + MTLO = 0x13, + MULT = 0x18, + MULTU = 0x19, + DIV = 0x1A, + DIVU = 0x1B, + ADD = 0x20, + ADDU = 0x21, + SUB = 0x22, + SUBU = 0x23, + AND = 0x24, + OR = 0x25, + XOR = 0x26, + NOR = 0x27, + SLT = 0x2A, + SLTU = 0x2B, + } + + public enum Cop + { + + MFC = 0x00, + CFC = 0x02, + MTC = 0x04, + CTC = 0x06, + BC = 0x10, + } + + // R-type instructions + public static uint SLL(uint dst, uint src, uint value) => (uint)Special.SLL | (dst << 11) | (src << 16) | ((value & 0x1Fu) << 6); + public static uint SRL(uint dst, uint src, uint value) => (uint)Special.SRL | (dst << 11) | (src << 16) | ((value & 0x1Fu) << 6); + public static uint SRA(uint dst, uint src, uint value) => (uint)Special.SRA | (dst << 11) | (src << 16) | ((value & 0x1Fu) << 6); + public static uint SLLV(uint dst, uint left, uint right) => (uint)Special.SLLV | (dst << 11) | left << 16 | right << 21; + public static uint SRAV(uint dst, uint left, uint right) => (uint)Special.SRAV | (dst << 11) | left << 16 | right << 21; + public static uint SRLV(uint dst, uint left, uint right) => (uint)Special.SRLV | (dst << 11) | left << 16 | right << 21; + public static uint JR(uint reg) => (uint)Special.JR | ((reg) << 21); + public static uint JALR(uint reg) => (uint)Special.JALR | ((reg) << 21); + public static uint SYSCALL(uint code) => (uint)Special.SYSCALL | ((code & 0xffffffu) << 6); + public static uint BREAK(uint code1, uint code2) => (uint)Special.BREAK | ((code1 & 0x3ffu) << 16) | ((code2 & 0x3ffu) << 6); + public static uint MFHI(uint reg) => (uint)Special.MFHI | ((reg) << 11); + public static uint MTHI(uint reg) => (uint)Special.MTHI | ((reg) << 11); + public static uint MFLO(uint reg) => (uint)Special.MFLO | ((reg) << 11); + public static uint MTLO(uint reg) => (uint)Special.MTLO | ((reg) << 11); + public static uint MULT(uint dst, uint src) => (uint)Special.MULT | (src << 16) | (dst << 21); + public static uint MULTU(uint dst, uint src) => (uint)Special.MULTU | (src << 16) | (dst << 21); + public static uint DIV(uint dst, uint src) => (uint)Special.DIV | (src << 16) | (dst << 21); + public static uint DIVU(uint dst, uint src) => (uint)Special.DIVU | (src << 16) | (dst << 21); + public static uint ADD(uint dst, uint left, uint right) => (uint)Special.ADD | (dst << 11) | (left << 21) | (right << 16); + public static uint ADDU(uint dst, uint left, uint right) => (uint)Special.ADDU | (dst << 11) | (left << 21) | (right << 16); + public static uint SUB(uint dst, uint left, uint right) => (uint)Special.SUB | (dst << 11) | (left << 21) | (right << 16); + public static uint SUBU(uint dst, uint left, uint right) => (uint)Special.SUBU | (dst << 11) | (left << 21) | (right << 16); + public static uint AND(uint dst, uint left, uint right) => (uint)Special.AND | (dst << 11) | (left << 21) | (right << 16); + public static uint OR(uint dst, uint left, uint right) => (uint)Special.OR | (dst << 11) | (left << 21) | (right << 16); + public static uint XOR(uint dst, uint left, uint right) => (uint)Special.XOR | (dst << 11) | (left << 21) | (right << 16); + public static uint NOR(uint dst, uint left, uint right) => (uint)Special.NOR | (dst << 11) | (left << 21) | (right << 16); + public static uint SLT(uint dst, uint left, uint right) => (uint)Special.SLT | (dst << 11) | (left << 21) | (right << 16); + public static uint SLTU(uint dst, uint left, uint right) => (uint)Special.SLTU | (dst << 11) | (left << 21) | (right << 16); + + // Alias R-type instructions + public static uint NOP() => SLL(Zero, Zero, 0u); + public static uint MOVE(uint dst, uint src) => OR(dst, src, Zero); + public static uint NEG(uint dst, uint src) => SUB(dst, Zero, src); + public static uint NEGU(uint dst, uint src) => SUBU(dst, Zero, src); + + // I-type instructions + public static uint BLTZ(uint reg, short imm) => (ushort)imm | ((uint)Regimm.BLTZ << 16) | (reg << 21) | ((uint)Op.REGIMM << 26); + public static uint BGEZ(uint reg, short imm) => (ushort)imm | ((uint)Regimm.BGEZ << 16) | (reg << 21) | ((uint)Op.REGIMM << 26); + public static uint BLTZAL(uint reg, short imm) => (ushort)imm | ((uint)Regimm.BLTZAL << 16) | (reg << 21) | ((uint)Op.REGIMM << 26); + public static uint BGEZAL(uint reg, short imm) => (ushort)imm | ((uint)Regimm.BGEZAL << 16) | (reg << 21) | ((uint)Op.REGIMM << 26); + public static uint BEQ(uint left, uint right, short imm) => (ushort)imm | (right << 16) | (left << 21) | ((uint)Op.BEQ << 26); + public static uint BNE(uint left, uint right, short imm) => (ushort)imm | (right << 16) | (left << 21) | ((uint)Op.BNE << 26); + public static uint BLEZ(uint reg, short imm) => (ushort)imm | (reg << 21) | ((uint)Op.BLEZ << 26); + public static uint BGTZ(uint reg, short imm) => (ushort)imm | (reg << 21) | ((uint)Op.BGTZ << 26); + public static uint ADDI(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.ADDI << 26); + public static uint ADDIU(uint dst, uint src, ushort imm) => imm | (dst << 16) | (src << 21) | ((uint)Op.ADDIU << 26); + public static uint ADDIU(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.ADDIU << 26); + public static uint SLTI(uint left, uint right, short imm) => (ushort)imm | (left << 16) | (right << 21) | ((uint)Op.SLTI << 26); + public static uint SLTIU(uint left, uint right, short imm) => (ushort)imm | (left << 16) | (right << 21) | ((uint)Op.SLTIU << 26); + public static uint ANDI(uint dst, uint src, ushort imm) => imm | (dst << 16) | (src << 21) | ((uint)Op.ANDI << 26); + public static uint ORI(uint dst, uint src, ushort imm) => imm | (dst << 16) | (src << 21) | ((uint)Op.ORI << 26); + public static uint XORI(uint dst, uint src, ushort imm) => imm | (dst << 16) | (src << 21) | ((uint)Op.XORI << 26); + public static uint LUI(uint dst, ushort imm) => imm | (dst << 16) | ((uint)Op.LUI << 26); + public static uint LB(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LB << 26); + public static uint LH(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LH << 26); + public static uint LWL(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LWL << 26); + public static uint LW(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LW << 26); + public static uint LBU(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LBU << 26); + public static uint LHU(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LHU << 26); + public static uint LWR(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LWR << 26); + public static uint SB(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SB << 26); + public static uint SH(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SH << 26); + public static uint SWL(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SWL << 26); + public static uint SW(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SW << 26); + public static uint SWR(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SWR << 26); + + // Alias I-type instructions + public static uint BAL(uint reg, short imm) => BGEZAL(reg, imm); + public static uint LI(uint dst, short imm) => ADDIU(dst, Zero, (ushort)imm); + public static uint LIU(uint dst, ushort imm) => ORI(dst, Zero, imm); + + // Co-processor instructions + public static uint MFC0(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MFC << 21) | ((uint)Op.C0 << 26); + public static uint MFC1(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MFC << 21) | ((uint)Op.C1 << 26); + public static uint MFC2(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MFC << 21) | ((uint)Op.C2 << 26); + public static uint MFC3(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MFC << 21) | ((uint)Op.C3 << 26); + public static uint MTC0(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MTC << 21) | ((uint)Op.C0 << 26); + public static uint MTC1(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MTC << 21) | ((uint)Op.C1 << 26); + public static uint MTC2(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MTC << 21) | ((uint)Op.C2 << 26); + public static uint MTC3(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.MTC << 21) | ((uint)Op.C3 << 26); + public static uint CFC0(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CFC << 21) | ((uint)Op.C0 << 26); + public static uint CFC1(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CFC << 21) | ((uint)Op.C1 << 26); + public static uint CFC2(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CFC << 21) | ((uint)Op.C2 << 26); + public static uint CFC3(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CFC << 21) | ((uint)Op.C3 << 26); + public static uint CTC0(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CTC << 21) | ((uint)Op.C0 << 26); + public static uint CTC1(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CTC << 21) | ((uint)Op.C1 << 26); + public static uint CTC2(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CTC << 21) | ((uint)Op.C2 << 26); + public static uint CTC3(uint dst, uint src) => ((src & 0x1Fu) << 11) | (dst << 16) | ((uint)Cop.CTC << 21) | ((uint)Op.C3 << 26); + public static uint COP0(uint offset) => (offset & 0x1FFFFFFu) | (1u << 25) | ((uint)Op.C0 << 26); + public static uint COP1(uint offset) => (offset & 0x1FFFFFFu) | (1u << 25) | ((uint)Op.C1 << 26); + public static uint COP2(uint offset) => (offset & 0x1FFFFFFu) | (1u << 25) | ((uint)Op.C2 << 26); + public static uint COP3(uint offset) => (offset & 0x1FFFFFFu) | (1u << 25) | ((uint)Op.C3 << 26); + public static uint LWC0(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LWC0 << 26); + public static uint LWC1(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LWC1 << 26); + public static uint LWC2(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LWC2 << 26); + public static uint LWC3(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.LWC3 << 26); + public static uint SWC0(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SWC0 << 26); + public static uint SWC1(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SWC1 << 26); + public static uint SWC2(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SWC2 << 26); + public static uint SWC3(uint dst, uint src, short imm) => (ushort)imm | (dst << 16) | (src << 21) | ((uint)Op.SWC3 << 26); + public static uint BC0F(short offset) => (ushort)offset | (0x10u << 26) | (0x10u << 20) | (0u << 16); + public static uint BC0T(short offset) => (ushort)offset | (0x10u << 26) | (0x10u << 20) | (1u << 16); + public static uint BC1F(short offset) => (ushort)offset | (0x11u << 26) | (0x10u << 20) | (0u << 16); + public static uint BC1T(short offset) => (ushort)offset | (0x11u << 26) | (0x10u << 20) | (1u << 16); + public static uint BC2F(short offset) => (ushort)offset | (0x12u << 26) | (0x10u << 20) | (0u << 16); + public static uint BC2T(short offset) => (ushort)offset | (0x12u << 26) | (0x10u << 20) | (1u << 16); + public static uint BC3F(short offset) => (ushort)offset | (0x13u << 26) | (0x10u << 20) | (0u << 16); + public static uint BC3T(short offset) => (ushort)offset | (0x13u << 26) | (0x10u << 20) | (1u << 16); + + // J-type instructions + public static uint J(uint addr) => (addr & 0x3FFFFFFu) | ((uint)Op.J << 26); + public static uint JAL(uint addr) => ((addr / 4) & 0x3FFFFFFu) | ((uint)Op.JAL << 26); + + // PlayStation 2 specific instructions + public static uint LD(uint src, uint dst, short imm) => (ushort)imm | (src << 16) | (dst << 21) | ((uint)Op.LD << 26); + public static uint SD(uint src, uint dst, short imm) => (ushort)imm | (src << 16) | (dst << 21) | ((uint)Op.SD << 26); + } +} diff --git a/OpenKh.Tools.ModManager/Classes/PINEStream.cs b/OpenKh.Tools.ModManager/Classes/PINEStream.cs new file mode 100644 index 000000000..933babe0d --- /dev/null +++ b/OpenKh.Tools.ModManager/Classes/PINEStream.cs @@ -0,0 +1,487 @@ +using System; +using System.IO; +using System.Net.Sockets; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Linq; +using System.Net; +using System.Diagnostics; + +namespace OpenKh.Tools.ModManager.Classes +{ + public sealed class PINEStream : Stream + { + struct PINE_MESSAGE + { + public PINE_COMMAND Command; + public uint Address; + public object? Data; + + public uint Length => 0x05 + (Data == null ? 0x00 : (uint)Marshal.SizeOf(Data)); + + public byte[] ToArray() + { + var _fetchData = new byte[Length]; + var _fetchSpan = _fetchData.AsSpan(0x05, Data == null ? 0x00 : Marshal.SizeOf(Data)); + + _fetchData[0] = (byte)Command; + + BinaryPrimitives.WriteUInt32LittleEndian(_fetchData.AsSpan(0x01, 0x04), Address); + + switch (Data) + { + case null: + break; + + case byte value: + _fetchData[0x05] = value; + break; + + case ushort value: + BinaryPrimitives.WriteUInt16LittleEndian( + _fetchSpan, + value); + break; + + case uint value: + BinaryPrimitives.WriteUInt32LittleEndian( + _fetchSpan, + value); + break; + + case ulong value: + BinaryPrimitives.WriteUInt64LittleEndian( + _fetchSpan, + value); + break; + + default: + throw new NotSupportedException( + $"Data type {Data?.GetType().Name} is not supported."); + } + + return _fetchData.ToArray(); + } + } + + enum PINE_COMMAND : byte + { + READ_INT08, + READ_INT16, + READ_INT32, + READ_INT64, + + WRITE_INT08, + WRITE_INT16, + WRITE_INT32, + WRITE_INT64 + }; + + enum PINE_RESPONSE : byte + { + IPC_OK, + IPC_FAIL = 0xFF + }; + + const int MAX_SEND_LENGTH = 640000; + const int MAX_RECEIVE_LENGTH = 440000; + + readonly object _syncLock = new(); + readonly string _socketPath; + + Socket? _mainSocket; + + uint _currPosition; + + bool _isValid; + bool _hasDisposed; + + public PINEStream(int slot = 28011) + { + if (OperatingSystem.IsLinux()) + { + TRY_SOCK_CONNECT: + + if (slot < 1 || slot > 65535) + throw new ArgumentOutOfRangeException(nameof(slot)); + + var _fetchRuntimePath = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR"); + + _socketPath = String.IsNullOrEmpty(_fetchRuntimePath) ? "/tmp/pcsx2.sock" : Path.Combine(_fetchRuntimePath, "pcsx2.sock"); + + if (slot != 28011) + _socketPath += "." + slot; + + var _fetchSocket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); + + try + { + var _fetchEndPoint = new UnixDomainSocketEndPoint(_socketPath); + _fetchSocket.Connect(_fetchEndPoint); + + _mainSocket = _fetchSocket; + } + + catch + { + _fetchSocket.Dispose(); + _fetchSocket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); + + _socketPath = "/tmp/pcsx2.sock"; + + if (slot != 28011) + _socketPath += "." + slot; + + try + { + var _fetchEndPoint = new UnixDomainSocketEndPoint(_socketPath); + _fetchSocket.Connect(_fetchEndPoint); + + _mainSocket = _fetchSocket; + } + + catch + { + _fetchSocket.Dispose(); + goto TRY_SOCK_CONNECT; + } + } + } + + else + { + if (slot < 1 || slot > 65535) + throw new ArgumentOutOfRangeException(nameof(slot)); + + try + { + var socket = new Socket( + AddressFamily.InterNetwork, + SocketType.Stream, + ProtocolType.Tcp + ); + + socket.Connect(IPAddress.Loopback, slot); + + _mainSocket = socket; + _isValid = true; + } + catch (SocketException) + { + _mainSocket = null; + _isValid = false; + } + } + + _isValid = _mainSocket != null; + } + + public override bool CanRead => !_hasDisposed && _isValid; + public override bool CanSeek => !_hasDisposed && _isValid; + public override bool CanWrite => !_hasDisposed && _isValid; + + public override long Length => UInt32.MaxValue + 1L; + + public override long Position + { + get + { + lock (_syncLock) + return _currPosition; + } + + set => Seek(value, SeekOrigin.Begin); + } + + public override long Seek(long offset, SeekOrigin origin) + { + lock (_syncLock) + { + if (origin == SeekOrigin.End) + throw new ArgumentException("Invalid seek origin.", nameof(origin)); + + var _calcPosition = origin == SeekOrigin.Begin ? (uint)offset : (uint)(_currPosition + offset); + + if (_calcPosition >= UInt32.MaxValue || _calcPosition < 0x00) + throw new ArgumentOutOfRangeException(); + + return _currPosition = _calcPosition; + } + } + + public override int Read(byte[] buffer, int offset, int count) + { + lock (_syncLock) + { + uint _initialPosition = _currPosition; + uint _pastByteLength = 0x00; + + if (_hasDisposed) + throw new ObjectDisposedException(nameof(PINEStream)); + + if (!_isValid) + throw new InvalidOperationException("PINE stream is not valid."); + + if (buffer == null) + throw new ArgumentNullException(nameof(buffer)); + + if (offset < 0 || count <= 0 || offset > buffer.Length - count || count > Length - _currPosition) + throw new ArgumentOutOfRangeException(); + + for (uint _packageLength = 0x00, _packageBytes = 0x00, _packageReceive = 0x00; _packageBytes < count;) + { + var _makePacket = new List(); + var _messageList = new List(); + + for (; _packageLength < MAX_SEND_LENGTH - 0x04 && _packageReceive < MAX_RECEIVE_LENGTH - 0x04 && _packageBytes < count;) + { + var _byteRemain = count - _packageBytes; + + var _makeMessage = new PINE_MESSAGE + { + Command = _byteRemain >= 0x08 ? PINE_COMMAND.READ_INT64 : + _byteRemain >= 0x04 ? PINE_COMMAND.READ_INT32 : + _byteRemain >= 0x02 ? PINE_COMMAND.READ_INT16 : PINE_COMMAND.READ_INT08, + + Address = _initialPosition + _packageBytes + }; + + _messageList.Add(_makeMessage); + _makePacket.AddRange(_makeMessage.ToArray()); + + var _currLength = _byteRemain >= 0x08 ? 0x08U : + _byteRemain >= 0x04 ? 0x04U : + _byteRemain >= 0x02 ? 0x02U : 0x01U; + + _packageBytes += _currLength; + _packageReceive += _currLength; + + _packageLength += _makeMessage.Length; + } + + var _finalSize = _makePacket.Count + 0x04; + _makePacket.InsertRange(0x00, BitConverter.GetBytes(_finalSize)); + + int _fetchSend = _mainSocket.Send(_makePacket.ToArray(), SocketFlags.None); + + var _fetchHeaderResponse = new byte[0x04]; + int _fetchResponse = _mainSocket.Receive(_fetchHeaderResponse, SocketFlags.None); + + if (_fetchSend <= 0x00 || _fetchResponse <= 0x00) + throw new IOException("PINE socket closed."); + + var _lengthResponse = BinaryPrimitives.ReadUInt32LittleEndian(_fetchHeaderResponse); + + if (_lengthResponse < 0x05 || _lengthResponse > 0x6DDD0) + throw new IOException("Invalid PINE response."); + + var _fetchDataResponse = new byte[_lengthResponse]; + int _fetchResult = _mainSocket.Receive(_fetchDataResponse, SocketFlags.None); + + if (_fetchResult <= 0) + throw new IOException("PINE socket closed."); + + var _fetchCodeResponse = _fetchDataResponse[0x00]; + + if (_fetchCodeResponse == (byte)PINE_RESPONSE.IPC_FAIL) + return (int) _packageBytes; + + if (_fetchCodeResponse != (byte)PINE_RESPONSE.IPC_OK) + throw new IOException($"Unknown PINE response: 0x{_fetchCodeResponse.ToString("X2")}"); + + for (int s = 0; s < _fetchDataResponse.Length - 0x05;) + { + var _fetchOffset = offset + s + (int)_pastByteLength; + var _byteRemain = _fetchDataResponse.Length - 0x05 - s; + + var _readLength = _byteRemain >= 0x08 ? 0x08 : + _byteRemain >= 0x04 ? 0x04 : + _byteRemain >= 0x02 ? 0x02 : 0x01; + + var _fetchSpanRead = _fetchDataResponse.AsSpan(0x01 + s, _readLength); + var _fetchSpanWrite = buffer.AsSpan(_fetchOffset, _readLength); + + switch (_readLength) + { + case 0x08: + { + var _fetchData = BinaryPrimitives.ReadUInt64LittleEndian(_fetchSpanRead); + BinaryPrimitives.WriteUInt64LittleEndian(_fetchSpanWrite, _fetchData); + } + break; + + case 0x04: + { + var _fetchData = BinaryPrimitives.ReadUInt32LittleEndian(_fetchSpanRead); + BinaryPrimitives.WriteUInt32LittleEndian(_fetchSpanWrite, _fetchData); + } + break; + + case 0x02: + { + var _fetchData = BinaryPrimitives.ReadUInt16LittleEndian(_fetchSpanRead); + BinaryPrimitives.WriteUInt16LittleEndian(_fetchSpanWrite, _fetchData); + } + break; + + default: + buffer[_fetchOffset] = _fetchDataResponse[0x05]; + break; + } + + s += _readLength; + } + + _pastByteLength = _packageBytes; + _currPosition = _initialPosition + _packageBytes; + + _packageReceive = 0x00; + _packageLength = 0x00; + } + + return count; + } + } + + public override void Write(byte[] buffer, int offset, int count) + { + lock (_syncLock) + { + uint _initialPosition = _currPosition; + + if (_hasDisposed || !_isValid) + throw new ObjectDisposedException(nameof(PINEStream)); + + if (buffer == null) + throw new ArgumentNullException(); + + if (offset < 0 || count <= 0 || offset > buffer.Length - count || count > Length - _initialPosition) + throw new ArgumentOutOfRangeException(); + + for (uint _packageLength = 0x00, _packageBytes = 0x00; _packageBytes < count;) + { + var _makePacket = new List(); + var _messageList = new List(); + + for (; _packageLength < MAX_SEND_LENGTH - 0x04 && _packageBytes < count;) + { + var _makeMessage = new PINE_MESSAGE(); + + var _fetchRemain = count - _packageBytes; + var _fetchOffset = (int) (offset + _packageBytes); + + _makeMessage.Address = _initialPosition + _packageBytes; + + if (_fetchRemain >= 0x08) + { + _makeMessage.Command = PINE_COMMAND.WRITE_INT64; + + var _fetchSpan = buffer.AsSpan(_fetchOffset, 0x08); + _makeMessage.Data = BinaryPrimitives.ReadUInt64LittleEndian(_fetchSpan); + + _packageBytes += 0x08; + } + + else if (_fetchRemain >= 0x04) + { + _makeMessage.Command = PINE_COMMAND.WRITE_INT32; + + var _fetchSpan = buffer.AsSpan(_fetchOffset, 0x04); + _makeMessage.Data = BinaryPrimitives.ReadUInt32LittleEndian(_fetchSpan); + + _packageBytes += 0x04; + } + + else if (_fetchRemain >= 0x02) + { + _makeMessage.Command = PINE_COMMAND.WRITE_INT16; + + var _fetchSpan = buffer.AsSpan(_fetchOffset, 0x02); + _makeMessage.Data = BinaryPrimitives.ReadUInt16LittleEndian(_fetchSpan); + + + _packageBytes += 0x02; + } + + else + { + _makeMessage.Command = PINE_COMMAND.WRITE_INT08; + _makeMessage.Data = buffer[_fetchOffset]; + + _packageBytes++; + } + + _messageList.Add(_makeMessage); + _makePacket.AddRange(_makeMessage.ToArray()); + + _packageLength += _makeMessage.Length; + } + + var _finalSize = _makePacket.Count + 0x04; + _makePacket.InsertRange(0x00, BitConverter.GetBytes(_finalSize)); + + int _fetchSend = _mainSocket.Send(_makePacket.ToArray(), SocketFlags.None); + + var _fetchHeaderResponse = new byte[0x04]; + int _fetchResponse = _mainSocket.Receive(_fetchHeaderResponse, SocketFlags.None); + + if (_fetchSend <= 0x00 || _fetchResponse <= 0x00) + throw new IOException("PINE socket closed."); + + var _lengthResponse = BinaryPrimitives.ReadUInt32LittleEndian(_fetchHeaderResponse); + + if (_lengthResponse < 0x05 || _lengthResponse > 0x6DDD0) + throw new IOException("Invalid PINE response."); + + var _fetchDataResponse = new byte[_lengthResponse]; + int _fetchResult = _mainSocket.Receive(_fetchDataResponse, SocketFlags.None); + + if (_fetchResult <= 0) + throw new IOException("PINE socket closed."); + + var _fetchCodeResponse = _fetchDataResponse[0x04]; + + if (_fetchCodeResponse == (byte)PINE_RESPONSE.IPC_FAIL) + return; + + if (_fetchCodeResponse != (byte)PINE_RESPONSE.IPC_OK) + throw new IOException($"Unknown PINE response: 0x{_fetchCodeResponse.ToString("X2")}"); + + _currPosition = _initialPosition + _packageBytes; + _packageLength = 0x00; + } + } + } + + public override void Flush() { } + + public override void SetLength(long value) => throw new NotSupportedException(); + + protected override void Dispose(bool disposing) + { + if (!_hasDisposed) + { + lock (_syncLock) + { + var _fetchSocket = _mainSocket; + _mainSocket = null; + + if (_fetchSocket != null) + { + try + { _fetchSocket.Shutdown(SocketShutdown.Both); } + catch { } + + _fetchSocket.Dispose(); + } + + _hasDisposed = true; + _isValid = false; + } + } + + base.Dispose(disposing); + } + } +} diff --git a/OpenKh.Tools.ModManager/Classes/SafePtr.cs b/OpenKh.Tools.ModManager/Classes/SafePtr.cs new file mode 100644 index 000000000..5af50a068 --- /dev/null +++ b/OpenKh.Tools.ModManager/Classes/SafePtr.cs @@ -0,0 +1,84 @@ +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace OpenKh.Tools.ModManager.Classes +{ + public class SafePtr : IDisposable + { + protected IntPtr _internalPtr; + protected Type _internalType; + + public SafePtr(object value) + { + _internalType = value.GetType(); + _internalPtr = Marshal.AllocHGlobal(value is string ? 255 : Marshal.SizeOf(_internalType)); + + if (value is byte) + Marshal.WriteByte(_internalPtr, (byte)value); + + else if (value is short) + Marshal.WriteInt16(_internalPtr, (short)value); + + else if (value is int) + Marshal.WriteInt32(_internalPtr, (int)value); + + else if (value is long) + Marshal.WriteInt64(_internalPtr, (long)value); + + else if (value is double) + Marshal.WriteInt64(_internalPtr, BitConverter.DoubleToInt64Bits((double)value)); + + else if (value is string) + { + var _fetchString = (value as string) + "\x00"; + var _fetchEncoding = Encoding.Default.GetBytes(_fetchString); + Marshal.Copy(_fetchEncoding, 0, _internalPtr, _fetchEncoding.Length); + } + + else + throw new InvalidCastException("SafePtr does not support this type!"); + } + + public static implicit operator SafePtr(byte value) => new SafePtr(value); + public static implicit operator SafePtr(short value) => new SafePtr(value); + public static implicit operator SafePtr(int value) => new SafePtr(value); + public static implicit operator SafePtr(long value) => new SafePtr(value); + public static implicit operator SafePtr(string value) => new SafePtr(value); + public static implicit operator SafePtr(double value) => new SafePtr(value); + + public void operator /= (byte value) => Marshal.WriteByte(_internalPtr, value); + public void operator /= (short value) => Marshal.WriteInt16(_internalPtr, value); + public void operator /= (int value) => Marshal.WriteInt32(_internalPtr, value); + public void operator /= (long value) => Marshal.WriteInt64(_internalPtr, value); + public void operator /= (double value) => Marshal.WriteInt64(_internalPtr, BitConverter.DoubleToInt64Bits(value)); + public void operator /= (string value) + { + var _fetchString = value + "\x00"; + var _fetchEncoding = Encoding.Default.GetBytes(_fetchString); + Marshal.Copy(_fetchEncoding, 0, _internalPtr, _fetchEncoding.Length); + } + + public static implicit operator byte?(SafePtr value) => value == null || value._internalPtr == IntPtr.Zero ? null : Marshal.ReadByte(value._internalPtr); + public static implicit operator short?(SafePtr value) => value == null || value._internalPtr == IntPtr.Zero ? null : Marshal.ReadInt16(value._internalPtr); + public static implicit operator int?(SafePtr value) => value == null || value._internalPtr == IntPtr.Zero ? null : Marshal.ReadInt32(value._internalPtr); + public static implicit operator long?(SafePtr value) => value == null || value._internalPtr == IntPtr.Zero ? null : Marshal.ReadInt64(value._internalPtr); + public static implicit operator double?(SafePtr value) => value == null || value._internalPtr == IntPtr.Zero ? null : BitConverter.Int64BitsToDouble(Marshal.ReadInt64(value._internalPtr)); + public static implicit operator string?(SafePtr value) + { + var _fetchValue = new byte[0xFF]; + + if (value == null || value._internalPtr == IntPtr.Zero) + return null; + + Marshal.Copy(value._internalPtr, _fetchValue, 0, 0xFF); + return Encoding.Default.GetString(_fetchValue, 0x00, _fetchValue.IndexOf(0x00)); + } + + public void Dispose() + { + Marshal.FreeHGlobal(_internalPtr); + _internalPtr = IntPtr.Zero; + } + } +} diff --git a/OpenKh.Tools.ModManager/Controls/ModDetailsControl.axaml b/OpenKh.Tools.ModManager/Controls/ModDetailsControl.axaml new file mode 100644 index 000000000..c7274f2ae --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModDetailsControl.axaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenKh.Tools.ModManager/Controls/ModDetailsControl.axaml.cs b/OpenKh.Tools.ModManager/Controls/ModDetailsControl.axaml.cs new file mode 100644 index 000000000..283371644 --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModDetailsControl.axaml.cs @@ -0,0 +1,16 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using System; + +namespace OpenKh.Tools.ModManager.Views +{ + public partial class ModDetailsView : ContentPage + { + public ModDetailsView() + { + InitializeComponent(); + } + } +} diff --git a/OpenKh.Tools.ModManager/Controls/ModListControl.axaml b/OpenKh.Tools.ModManager/Controls/ModListControl.axaml new file mode 100644 index 000000000..e001a0f5a --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModListControl.axaml @@ -0,0 +1,42 @@ + + + + M6.5 4C3.46243 4 1 6.46243 1 9.5C1 11.8359 2.45624 13.8317 4.51041 14.6291C4.54977 13.9293 4.69984 13.2591 4.94339 12.6357C3.79151 12.0627 3 10.8738 3 9.5C3 7.567 4.567 6 6.5 6H12.5C14.433 6 16 7.567 16 9.5C16 11.433 14.433 13 12.5 13H12C11.4477 13 11 13.4477 11 14C11 14.5523 11.4477 15 12 15H12.5C15.5376 15 18 12.5376 18 9.5C18 6.46243 15.5376 4 12.5 4H6.5ZM19.1135 12.2134C20.219 12.6556 21 13.7366 21 15C21 16.6569 19.6569 18 18 18H11C9.34315 18 8 16.6569 8 15C8 13.3431 9.34315 12 11 12H12C12.5523 12 13 11.5523 13 11C13 10.4477 12.5523 10 12.0001 10H11C8.23858 10 6 12.2386 6 15C6 17.7614 8.23858 20 11 20H18C20.7614 20 23 17.7614 23 15C23 12.7598 21.5267 10.8636 19.4962 10.2277C19.4722 10.9229 19.3391 11.5903 19.1135 12.2134Z + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenKh.Tools.ModManager/Controls/ModListControl.axaml.cs b/OpenKh.Tools.ModManager/Controls/ModListControl.axaml.cs new file mode 100644 index 000000000..3d3a7568c --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModListControl.axaml.cs @@ -0,0 +1,37 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using OpenKh.Tools.ModManager.Models; +using OpenKh.Tools.ModManager.ViewModels; +using System; +using System.Collections.Generic; +using System.Windows.Input; + +namespace OpenKh.Tools.ModManager.Views +{ + public partial class ModListView : ContentPage + { + public static readonly StyledProperty ModToggledProperty = AvaloniaProperty.Register(nameof(ModToggled)); + public ICommand? ModToggled { get => GetValue(ModToggledProperty); set => SetValue(ModToggledProperty, value); } + + public ModListView() + { + InitializeComponent(); + } + + private void OnModCheckChanged(object? sender, RoutedEventArgs e) + { + var _fetchSender = sender as CheckBox; + var _fetchParent = _fetchSender.Parent.DataContext as ModModel; + + if (_fetchParent == null) + return; + + var _targetTuple = new Tuple(_fetchParent, _fetchSender.IsChecked ?? false); + + if (ModToggled?.CanExecute(_targetTuple) == true) + ModToggled.Execute(_targetTuple); + } + } +} diff --git a/OpenKh.Tools.ModManager/Controls/ModStatusControl.axaml b/OpenKh.Tools.ModManager/Controls/ModStatusControl.axaml new file mode 100644 index 000000000..e2290854c --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModStatusControl.axaml @@ -0,0 +1,45 @@ + + + + M18 13C18.1678 13 18.3344 13.0083 18.498 13.0244C18.7956 13.0538 19.0252 13.2867 19.0878 13.5791L19.3544 14.8223C19.4237 15.146 19.7582 15.339 20.0732 15.2373L21.2822 14.8457C21.5662 14.754 21.882 14.837 22.0566 15.0791C22.2496 15.3471 22.417 15.6353 22.5546 15.9395C22.6778 16.2119 22.591 16.5271 22.3691 16.7275L21.4257 17.5801C21.1801 17.802 21.1801 18.1883 21.4257 18.4102L22.373 19.2646C22.5948 19.4648 22.6812 19.7804 22.5585 20.0527C22.4217 20.3565 22.2555 20.6443 22.0634 20.9121C21.889 21.1551 21.5717 21.2386 21.2871 21.1465L20.0732 20.7529C19.7582 20.6512 19.4237 20.8442 19.3544 21.168L19.0859 22.4199C19.0233 22.7124 18.7937 22.9457 18.496 22.9756C18.3331 22.9919 18.1672 23 18 23C17.8341 23 17.6695 22.9915 17.5078 22.9756C17.2099 22.946 16.9786 22.7136 16.916 22.4209L16.6494 21.168C16.5801 20.8442 16.2457 20.6511 15.9306 20.7529L14.7119 21.1465C14.4274 21.2382 14.1107 21.155 13.9365 20.9121C13.745 20.6451 13.5789 20.3584 13.4423 20.0557C13.3196 19.7834 13.4062 19.4678 13.6279 19.2676L14.5781 18.4102C14.8238 18.1883 14.8238 17.802 14.5781 17.5801L13.6308 16.7246C13.4088 16.5241 13.3218 16.208 13.4453 15.9355C13.5828 15.6321 13.7505 15.3445 13.9433 15.0771C14.1179 14.8353 14.4339 14.753 14.7177 14.8447L15.9306 15.2373C16.2457 15.3392 16.5801 15.1461 16.6494 14.8223L16.914 13.5791C16.9765 13.2865 17.2072 13.0541 17.5048 13.0244C17.6674 13.0084 17.8333 13 18 13ZM18 16.5C17.1719 16.5004 16.5 17.1718 16.5 18C16.5 18.8282 17.1719 19.4996 18 19.5C18.8284 19.5 19.5 18.8284 19.5 18C19.5 17.1716 18.8284 16.5 18 16.5ZM9.00776 1.49805C9.34737 1.49806 9.68098 1.52151 10.0068 1.56543L10.33 1.61621L10.4394 1.64453C10.6888 1.72927 10.8786 1.94064 10.9326 2.2041L11.2978 3.98633L11.3173 4.06055C11.4334 4.42205 11.8259 4.62709 12.1953 4.50391L13.9228 3.92773L14.0322 3.89941C14.2913 3.8546 14.5589 3.94943 14.7324 4.1543C15.3037 4.82893 15.7593 5.60646 16.0654 6.45605C16.1691 6.74458 16.0867 7.06796 15.8574 7.27148L14.4921 8.48242C14.1819 8.75784 14.1809 9.24216 14.4912 9.51758L15.8554 10.7266C16.0851 10.9302 16.1676 11.2542 16.0634 11.543C15.7567 12.3932 15.3011 13.1705 14.7294 13.8447C14.5313 14.0783 14.2105 14.168 13.9199 14.0713L12.1953 13.4961C11.8259 13.3729 11.4334 13.5779 11.3173 13.9395L11.2978 14.0137L10.9335 15.791C10.8719 16.0918 10.6332 16.3248 10.331 16.3789C9.90421 16.4549 9.46182 16.498 9.00776 16.498C8.54901 16.498 8.10153 16.455 7.6689 16.377C7.36709 16.3225 7.12887 16.0895 7.06733 15.7891L6.70503 14.0137C6.62183 13.6069 6.20142 13.3649 5.80757 13.4961L4.09175 14.0674C3.80095 14.1642 3.48023 14.0737 3.28218 13.8398C2.7102 13.1641 2.25332 12.3856 1.94722 11.5332C1.84354 11.2444 1.92649 10.9212 2.1562 10.7178L3.51167 9.51758C3.8217 9.24218 3.8217 8.75782 3.51167 8.48242L2.15522 7.28027C1.92584 7.07698 1.84288 6.75435 1.94624 6.46582C2.25177 5.61404 2.70754 4.83434 3.27925 4.1582L3.35835 4.07715C3.55642 3.90439 3.83422 3.8458 4.08882 3.93066L5.80757 4.50391C6.20142 4.63511 6.62183 4.39309 6.70503 3.98633L7.06831 2.20605L7.09858 2.09668C7.18953 1.85006 7.4057 1.66578 7.66987 1.61816C8.10313 1.5401 8.55035 1.49805 9.00776 1.49805ZM8.99995 6.75C7.75731 6.75 6.74995 7.75736 6.74995 9C6.74995 10.2426 7.75731 11.25 8.99995 11.25C10.2425 11.2499 11.25 10.2426 11.25 9C11.25 7.75739 10.2425 6.75005 8.99995 6.75Z + + + + + + + + + + + + diff --git a/OpenKh.Tools.ModManager/Controls/ModStatusControl.axaml.cs b/OpenKh.Tools.ModManager/Controls/ModStatusControl.axaml.cs new file mode 100644 index 000000000..c670df8a4 --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModStatusControl.axaml.cs @@ -0,0 +1,49 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Data.Converters; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using CommunityToolkit.Mvvm.Input; +using OpenKh.Bbs.SystemData; +using OpenKh.Tools.ModManager.Models; +using System; +using System.Globalization; +using System.Windows.Input; + +namespace OpenKh.Tools.ModManager.Views +{ + public partial class ModStatusView : ContentPage + { + public static readonly StyledProperty RunRequestedProperty = AvaloniaProperty.Register(nameof(RunRequested)); + public ICommand? RunRequested { get => GetValue(RunRequestedProperty); set => SetValue(RunRequestedProperty, value); } + + public static readonly StyledProperty BuildRunRequestedProperty = AvaloniaProperty.Register(nameof(BuildRunRequested)); + public ICommand? BuildRunRequested { get => GetValue(BuildRunRequestedProperty); set => SetValue(BuildRunRequestedProperty, value); } + + public static readonly StyledProperty SetupRequestedProperty = AvaloniaProperty.Register(nameof(SetupRequested)); + public ICommand? SetupRequested { get => GetValue(SetupRequestedProperty); set => SetValue(SetupRequestedProperty, value); } + + public ModStatusView() + { + InitializeComponent(); + } + + private void OnRunRequested(object? sender, RoutedEventArgs e) + { + if (RunRequested?.CanExecute(null) == true) + RunRequested.Execute(null); + } + + private void OnSetupRequested(object? sender, RoutedEventArgs e) + { + if (SetupRequested?.CanExecute(null) == true) + SetupRequested.Execute(null); + } + + private void OnBuildRunRequested(object? sender, RoutedEventArgs e) + { + if (BuildRunRequested?.CanExecute(null) == true) + BuildRunRequested.Execute(null); + } + } +} diff --git a/OpenKh.Tools.ModManager/Controls/ModWrapControl.axaml b/OpenKh.Tools.ModManager/Controls/ModWrapControl.axaml new file mode 100644 index 000000000..db07dc16e --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModWrapControl.axaml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenKh.Tools.ModManager/Controls/ModWrapControl.axaml.cs b/OpenKh.Tools.ModManager/Controls/ModWrapControl.axaml.cs new file mode 100644 index 000000000..927295c78 --- /dev/null +++ b/OpenKh.Tools.ModManager/Controls/ModWrapControl.axaml.cs @@ -0,0 +1,35 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using OpenKh.Tools.ModManager.Models; +using System; +using System.Windows.Input; + +namespace OpenKh.Tools.ModManager.Views +{ + public partial class ModWrapView : ContentPage + { + public static readonly StyledProperty ModSelectedRequestedProperty = AvaloniaProperty.Register(nameof(ModSelectedRequested)); + public ICommand? ModSelectedRequested { get => GetValue(ModSelectedRequestedProperty); set => SetValue(ModSelectedRequestedProperty, value); } + + public ModWrapView() + { + InitializeComponent(); + } + + private void OnModSelectedChanged(object? sender, RoutedEventArgs e) + { + var _fetchSender = sender as CheckBox; + var _fetchParent = _fetchSender.Parent.DataContext as ModModel; + + if (_fetchParent == null) + return; + + var _targetTuple = new Tuple(_fetchParent, _fetchSender.IsChecked ?? false); + + if (ModSelectedRequested?.CanExecute(_targetTuple) == true) + ModSelectedRequested.Execute(_targetTuple); + } + } +} diff --git a/OpenKh.Tools.ModManager/Converters/XamlConverters.cs b/OpenKh.Tools.ModManager/Converters/XamlConverters.cs new file mode 100644 index 000000000..8f01a547a --- /dev/null +++ b/OpenKh.Tools.ModManager/Converters/XamlConverters.cs @@ -0,0 +1,84 @@ +using Avalonia.Data; +using Avalonia.Data.Converters; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenKh.Tools.ModManager.Converters +{ + public class BooleanValueMapper : IValueConverter + { + public object? IfTrue { get; set; } + public object? IfFalse { get; set; } + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value is bool b && b ? IfTrue : IfFalse; + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException(); + } + + public class MultiBooleanCheckerConverter : IMultiValueConverter + { + public object Convert(IList values, Type targetType, object? parameter, CultureInfo culture) + { + if (values == null || values.Count < 2) + return false; + + return values.All(x => x is bool) && values.All(x => (bool)x); + } + } + + public class PropertyNotEqualConverter : IMultiValueConverter + { + public object Convert(IList values, Type targetType, object? parameter, CultureInfo culture) + { + if (values == null || values.Count != 2 || values[0] == null || values[1] == null) + return false; + + var _fetchFirst = (values[0] is Enum) ? System.Convert.ToInt32(values[0]) : values[0]; + var _fetchSecond = (values[1] is Enum) ? System.Convert.ToInt32(values[1]) : values[1]; + + return _fetchFirst is int a && _fetchSecond is int b && a != b; + } + } + public class PropertyIsEqualConverter : IMultiValueConverter + { + public object Convert(IList values, Type targetType, object? parameter, CultureInfo culture) + { + if (values == null || values.Count != 2 || values[0] == null || values[1] == null) + return false; + + var _fetchFirst = (values[0] is Enum) ? System.Convert.ToInt32(values[0]) : values[0]; + var _fetchSecond = (values[1] is Enum) ? System.Convert.ToInt32(values[1]) : values[1]; + + return _fetchFirst is int a && _fetchSecond is int b && a == b; + } + } + + public class NonNullPropertyConverter : IMultiValueConverter + { + public object Convert(IList values, Type targetType, object? parameter, CultureInfo culture) + { + if (values == null || values.Count < 2) + return false; + + return values[0] != null && values[1] is bool b && b; + } + } + + public class SubtractPropertyCalculator : IValueConverter + { + public object? IfTrue { get; set; } + public object? IfFalse { get; set; } + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + double _fetchValue = value != null && value is double d ? d : 0.0; + double _fetchSubtract = parameter != null && parameter is string str ? double.Parse(str) : 0.0; + + return _fetchValue - _fetchSubtract; + } + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException(); + } +} diff --git a/OpenKh.Tools.ModManager/Dialogs/InputDialog.axaml b/OpenKh.Tools.ModManager/Dialogs/InputDialog.axaml new file mode 100644 index 000000000..65ae94b2f --- /dev/null +++ b/OpenKh.Tools.ModManager/Dialogs/InputDialog.axaml @@ -0,0 +1,15 @@ + + + + + +