From 75d457a7ab997d312d5c530ec726cbcdab29337a Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 3 Jul 2026 19:10:58 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=97=E3=83=A9=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=81=8B=E3=82=89getinfo=E3=81=B8=E6=83=85=E5=A0=B1=E3=82=92?= =?UTF-8?q?=E4=BE=9B=E7=B5=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/Effects/LuaScriptEffectProcessor.cs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/LuaScript/Effects/LuaScriptEffectProcessor.cs b/LuaScript/Effects/LuaScriptEffectProcessor.cs index 660994b..e58259b 100644 --- a/LuaScript/Effects/LuaScriptEffectProcessor.cs +++ b/LuaScript/Effects/LuaScriptEffectProcessor.cs @@ -57,14 +57,26 @@ namespace LuaScript int GroupCount, int TimelineTotalFrame, double TimelineTotalTime, + double Bpm, + int BpmBeat, + double BpmOffset, int AnchorVersion, DrawDescription InputDesc ); private const int NativeTimeoutMilliseconds = 5000; - private static string NativeDirectory => - Path.Combine(Path.GetDirectoryName(typeof(LuaScriptEffectProcessor).Assembly.Location) ?? AppContext.BaseDirectory, "native"); + private static string PluginDirectory => + Path.GetDirectoryName(typeof(LuaScriptEffectProcessor).Assembly.Location) ?? AppContext.BaseDirectory; + + private static string NativeDirectory => Path.Combine(PluginDirectory, "native"); + + private static readonly string s_scriptPath = PluginDirectory + Path.DirectorySeparatorChar; + + private static readonly double s_hostVersion = EncodeVersion(AppVersion.Current); + + private static double EncodeVersion(Version version) => + version.Major * 10000 + version.Minor * 100 + Math.Max(0, version.Build); private readonly LuaScriptEngine _engine = new(static () => new MediaSourceLoader()); private readonly SemaphoreSlim _pixelLoaderSemaphore = new(1, 1); @@ -276,6 +288,8 @@ namespace LuaScript var inDesc = desc.DrawDescription; + var (bpm, bpmBeat, bpmOffset) = ResolveBpm(desc); + var key = new RenderKey( frame, time, length, fps, t0, t1, t2, t3, @@ -290,6 +304,7 @@ namespace LuaScript desc.GroupIndex, desc.GroupCount, desc.TimelineDuration.Frame, desc.TimelineDuration.Time.TotalSeconds, + bpm, bpmBeat, bpmOffset, item.AnchorVersion, inDesc); @@ -440,6 +455,25 @@ namespace LuaScript return _effectChain.Apply(source, requests, desc, target, ref drawDescription); } + private static (double Bpm, int Beat, double Offset) ResolveBpm(EffectDescription desc) + { + var scenes = desc.Scenes; + if (scenes is not null) + { + foreach (var info in scenes) + { + if (info is Scene scene && scene.ID == desc.SceneId) + { + var line = scene.Timeline.VerticalLine; + double tempo = line.Line is VerticalBPMLine bpm ? bpm.BPM : 0d; + double offset = desc.FPS > 0 ? line.StartFrame / (double)desc.FPS : 0d; + return (tempo, line.Group, offset); + } + } + } + return (0d, 0, 0d); + } + private static SceneObjectResolver BuildSceneObjectResolver(EffectDescription desc) { var scenes = desc.Scenes; @@ -610,6 +644,11 @@ namespace LuaScript ctx.IsPaused = key.Usage == TimelineSourceUsage.Paused; ctx.SceneId = ResolveSceneId(key.SceneId); ctx.TimeRatio = key.Length > 0 ? key.Frame / (double)key.Length : 0d; + ctx.ScriptPath = s_scriptPath; + ctx.HostVersion = s_hostVersion; + ctx.Bpm = key.Bpm; + ctx.BpmBeat = key.BpmBeat; + ctx.BpmOffset = key.BpmOffset; PopulateStringParameters(ctx); ctx.SceneScope = _hostDevices; ctx.BeginSceneValues(); @@ -879,7 +918,7 @@ namespace LuaScript private bool ExecuteNative(string script, AviUtlScriptContext ctx, RawRectF bounds, int imgW, int imgH) { - _nativeWorker ??= new LuaJitWorker(NativeDirectory); + _nativeWorker ??= new LuaJitWorker(NativeDirectory, s_scriptPath); _nativeFields ??= new double[NativeProtocol.FieldCount]; _nativeUpload ??= UploadNativeInputPixels; _nativeResolveObject ??= (tag, frame) => _context.ResolveObject(tag, frame, out var info) ? info : null;