Skip to content

Commit

Permalink
Fix reference scripts;
Browse files Browse the repository at this point in the history
  • Loading branch information
onepiecefreak3 committed Oct 19, 2024
1 parent 40aa8e0 commit ea95069
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IEnumerable<ConfigCategory> Load()

private string GetConfigPath()
{
return Path.Combine(Environment.ProcessPath!, "config.json");
return Path.Combine(Path.GetDirectoryName(Environment.ProcessPath)!, "config.json");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace Logic.Domain.Level5.Script.Xq32
internal class Xq32ScriptReader : ScriptReader<Xq32Function, Xq32Jump, Xq32Instruction, Xq32Argument>, IXq32ScriptReader
{
private readonly IBinaryFactory _binaryFactory;
private readonly Dictionary<uint, IList<string>> _functionCache;
private readonly Dictionary<uint, IList<string>> _jumpCache;
private readonly Dictionary<uint, HashSet<string>> _functionCache;
private readonly Dictionary<uint, HashSet<string>> _jumpCache;

public Xq32ScriptReader(IXq32ScriptDecompressor decompressor, IXq32ScriptEntrySizeProvider entrySizeProvider,
IBinaryFactory binaryFactory)
: base(decompressor, entrySizeProvider, binaryFactory)
{
_binaryFactory = binaryFactory;
_functionCache = new Dictionary<uint, IList<string>>();
_jumpCache = new Dictionary<uint, IList<string>>();
_functionCache = new Dictionary<uint, HashSet<string>>();
_jumpCache = new Dictionary<uint, HashSet<string>>();
}

public override IReadOnlyList<Xq32Function> ReadFunctions(Stream functionStream, int entryCount, PointerLength length)
Expand Down Expand Up @@ -185,8 +185,8 @@ protected override ScriptFunction CreateFunction(Xq32Function function, IBinaryR
stringReader.BaseStream.Position = function.nameOffset;
name = stringReader.ReadCStringSJIS();

if (!_functionCache.TryGetValue(function.crc32, out IList<string>? functionNames))
_functionCache[function.crc32] = functionNames = new List<string>();
if (!_functionCache.TryGetValue(function.crc32, out HashSet<string>? functionNames))
_functionCache[function.crc32] = functionNames = new HashSet<string>();

functionNames.Add(name);
}
Expand Down Expand Up @@ -216,8 +216,8 @@ protected override ScriptJump CreateJump(Xq32Jump jump, IBinaryReaderX? stringRe
stringReader.BaseStream.Position = jump.nameOffset;
name = stringReader.ReadCStringSJIS();

if (!_jumpCache.TryGetValue(jump.crc32, out IList<string>? jumpNames))
_jumpCache[jump.crc32] = jumpNames = new List<string>();
if (!_jumpCache.TryGetValue(jump.crc32, out HashSet<string>? jumpNames))
_jumpCache[jump.crc32] = jumpNames = new HashSet<string>();

jumpNames.Add(name);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ protected override ScriptArgument CreateArgument(Xq32Argument argument, int inst

if (argumentIndex != 0)
{
if (_functionCache.TryGetValue((ushort)argument.value, out IList<string>? names)
if (_functionCache.TryGetValue((ushort)argument.value, out HashSet<string>? names)
|| _jumpCache.TryGetValue((ushort)argument.value, out names))
value = names.First();
break;
Expand All @@ -271,22 +271,22 @@ protected override ScriptArgument CreateArgument(Xq32Argument argument, int inst
switch (instructionType)
{
case 20:
if (_functionCache.TryGetValue((ushort)argument.value, out IList<string>? names))
if (_functionCache.TryGetValue(argument.value, out HashSet<string>? names))
value = names.First();
break;

case 30:
if (_jumpCache.TryGetValue((ushort)argument.value, out names))
if (_jumpCache.TryGetValue(argument.value, out names))
value = names.First();
break;

case 31:
if (_jumpCache.TryGetValue((ushort)argument.value, out names))
if (_jumpCache.TryGetValue(argument.value, out names))
value = names.First();
break;

case 33:
if (_jumpCache.TryGetValue((ushort)argument.value, out names))
if (_jumpCache.TryGetValue(argument.value, out names))
value = names.First();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace Logic.Domain.Level5.Script.Xseq
internal class XseqScriptReader : ScriptReader<XseqFunction, XseqJump, XseqInstruction, XseqArgument>, IXseqScriptReader
{
private readonly IBinaryFactory _binaryFactory;
private readonly Dictionary<ushort, IList<string>> _functionCache;
private readonly Dictionary<ushort, IList<string>> _jumpCache;
private readonly Dictionary<ushort, HashSet<string>> _functionCache;
private readonly Dictionary<ushort, HashSet<string>> _jumpCache;

public XseqScriptReader(IXseqScriptDecompressor decompressor, IXseqScriptEntrySizeProvider entrySizeProvider,
IBinaryFactory binaryFactory)
: base(decompressor, entrySizeProvider, binaryFactory)
{
_binaryFactory = binaryFactory;
_functionCache = new Dictionary<ushort, IList<string>>();
_jumpCache = new Dictionary<ushort, IList<string>>();
_functionCache = new Dictionary<ushort, HashSet<string>>();
_jumpCache = new Dictionary<ushort, HashSet<string>>();
}

public override IReadOnlyList<XseqFunction> ReadFunctions(Stream functionStream, int entryCount, PointerLength length)
Expand Down Expand Up @@ -179,8 +179,8 @@ protected override ScriptFunction CreateFunction(XseqFunction function, IBinaryR
stringReader.BaseStream.Position = function.nameOffset;
name = stringReader.ReadCStringSJIS();

if (!_functionCache.TryGetValue(function.crc16, out IList<string>? functionNames))
_functionCache[function.crc16] = functionNames = new List<string>();
if (!_functionCache.TryGetValue(function.crc16, out HashSet<string>? functionNames))
_functionCache[function.crc16] = functionNames = new HashSet<string>();

functionNames.Add(name);
}
Expand Down Expand Up @@ -210,8 +210,8 @@ protected override ScriptJump CreateJump(XseqJump jump, IBinaryReaderX? stringRe
stringReader.BaseStream.Position = jump.nameOffset;
name = stringReader.ReadCStringSJIS();

if (!_jumpCache.TryGetValue(jump.crc16, out IList<string>? jumpNames))
_jumpCache[jump.crc16] = jumpNames = new List<string>();
if (!_jumpCache.TryGetValue(jump.crc16, out HashSet<string>? jumpNames))
_jumpCache[jump.crc16] = jumpNames = new HashSet<string>();

jumpNames.Add(name);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ protected override ScriptArgument CreateArgument(XseqArgument argument, int inst

if (argumentIndex != 0)
{
if (_functionCache.TryGetValue((ushort)argument.value, out IList<string>? names)
if (_functionCache.TryGetValue((ushort)argument.value, out HashSet<string>? names)
|| _jumpCache.TryGetValue((ushort)argument.value, out names))
value = names.First();
break;
Expand All @@ -265,7 +265,7 @@ protected override ScriptArgument CreateArgument(XseqArgument argument, int inst
switch (instructionType)
{
case 20:
if (_functionCache.TryGetValue((ushort)argument.value, out IList<string>? names))
if (_functionCache.TryGetValue((ushort)argument.value, out HashSet<string>? names))
value = names.First();
break;

Expand Down
22 changes: 12 additions & 10 deletions XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5/_Activator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ public void Register(ICoCoKernel kernel)
kernel.Register<IScriptWriterFactory, ScriptWriterFactory>(ActivationScope.Unique);
kernel.Register<IScriptEntrySizeProviderFactory, ScriptEntrySizeProviderFactory>(ActivationScope.Unique);

kernel.Register<IXq32ScriptDecompressor, Xq32ScriptDecompressor>();
kernel.Register<IXq32ScriptCompressor, Xq32ScriptCompressor>();
kernel.Register<IXq32ScriptDecompressor, Xq32ScriptDecompressor>(ActivationScope.Unique);
kernel.Register<IXq32ScriptCompressor, Xq32ScriptCompressor>(ActivationScope.Unique);
kernel.Register<IXq32ScriptReader, Xq32ScriptReader>(ActivationScope.Unique);
kernel.Register<IXq32ScriptWriter, Xq32ScriptWriter>(ActivationScope.Unique);
kernel.Register<IXq32ScriptEntrySizeProvider, Xq32ScriptEntrySizeProvider>(ActivationScope.Unique);

kernel.Register<IXq32StringTable, Xq32StringTable>();
kernel.Register<IXq32ScriptReader, Xq32ScriptReader>();
kernel.Register<IXq32ScriptWriter, Xq32ScriptWriter>();
kernel.Register<IXq32ScriptEntrySizeProvider, Xq32ScriptEntrySizeProvider>();

kernel.Register<IXseqScriptDecompressor, XseqScriptDecompressor>();
kernel.Register<IXseqScriptCompressor, XseqScriptCompressor>();
kernel.Register<IXseqScriptDecompressor, XseqScriptDecompressor>(ActivationScope.Unique);
kernel.Register<IXseqScriptCompressor, XseqScriptCompressor>(ActivationScope.Unique);
kernel.Register<IXseqScriptReader, XseqScriptReader>(ActivationScope.Unique);
kernel.Register<IXseqScriptWriter, XseqScriptWriter>(ActivationScope.Unique);
kernel.Register<IXseqScriptEntrySizeProvider, XseqScriptEntrySizeProvider>(ActivationScope.Unique);

kernel.Register<IXseqStringTable, XseqStringTable>();
kernel.Register<IXseqScriptReader, XseqScriptReader>();
kernel.Register<IXseqScriptWriter, XseqScriptWriter>();
kernel.Register<IXseqScriptEntrySizeProvider, XseqScriptEntrySizeProvider>();

kernel.RegisterConfiguration<Level5Configuration>();
}
Expand Down

0 comments on commit ea95069

Please sign in to comment.