--[[

偮偄偵丄擮婅偺儘儞僌僔儍僪乕僗僋儕僾僩偑嶌惉偝傟傑偟偨丅
傑偨丄怴偨偵rikky巵偺偛嫤椡偵傛傝丄rikky_module偲偙偺僗僋儕僾僩偺儖乕僾晹暘偺dll傪嶌惉偟偰偄偨偩偗傑偟偨(杮摉偵偁傝偑偲偆偛偞偄傑偡...!)

仧 摫擖 仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧
plugin僼僅儖僟乕偵丄rikky_module.dll偺尰嵼偺嵟怴僶乕僕儑儞偲丄
AviutlLongShadow.dll傪擖傟偰偔偩偝偄丅
傑偨丄偙偺僗僋儕僾僩帺懱偼sciprt僼僅儖僟乕埲壓偵擖傟偰偔偩偝偄丅

仧 愢柧 仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧
偱偼丄奺愢柧偩偗抳偟傑偡丅幚嵺偼怗偭偰傒偨傎偆偑傢偐傝傗偡偄偐偲巚偄傑偡丅

Length			:	僔儍僪乕偺挿偝丅
Angle			:	僔儍僪乕偺妏搙丅
AjustAlp			:	夋憸摟柧搙傪挷惍偟傑偡丅
					夋憸偺摟柧搙傪挷惍偡傞偺偱丄尦偺傾儖僼傽抣偑柍帇偝傟偰偟傑偆偲偙傠偑寚揰偱偡丅
Alpha			:	夋憸摟柧搙偺鑷抣丅摿偵僥僉僗僩偼僼僅儞僩偵傛偭偰旝挷惍昁恵偱偡丅
Bidirectional		:	憃曽岦偵僔儍僪乕傪怢偽偡偐斲偐丅

dialog
塭偺傒			:	僆僽僕僃僋僩偱偼側偔僔儍僪乕偺傒偺昤夋丅
color 			:	僔儍僪乕偺怓丅
僌儔僨乕僔儑儞		:	僔儍僪乕偵娭偟偰丄抂偵峴偗偽峴偔傎偳僌儔僨乕僔儑儞偡傞偐斲偐丅
GradColor		:	僌儔僨乕僔儑儞偺抂偺怓丅
					background偲偄偆暥帤楍傪擖傟傟偽攚宨偺怓傪揔梡偝偣傛偆偲偟傑偟偨偑丄
					偺偪偺僶乕僕儑儞偱摟柧搙傪幚憰偟傛偆偲峫偊偨偺偱丄幚憰偟偰偍傝傑偣傫丅
夞揮張棟			:	僆僽僕僃僋僩偺夞揮僩儔僢僋僶乕偱偺夞揮張棟偺曄峏丅
奼挘忋丄壓丄嵍丄塃		:	僔儍僪乕傪昤夋偡傞嵺丄椞堟奼挘傪幚峴偡傞偵偁偨偭偰愝掕偡傞抣偱偡丅

尰嵼偺偲偙傠忋婰偑幚憰偝傟偰偍傝傑偡丅
傑偨丄僶乕僕儑儞傾僢僾偵傛偭偰僔儍僪乕帺懱偺摟柧搙偑幚憰偝傟傞梊掕偱偡偺偱丄屻掱偍懸偪偔偩偝偄丅

--- versions 仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧
1.1 :	rikky_module偺峏怴偲偲傕偵丄AviutlLongShadow.dll傪峏怴丅
1.0	:	僗僋儕僾僩嶌惉丅

--- authors 仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧
script				:	Aodaruma	(@Aodaruma_)
dll,special thanks	:	rikky 		(@rikky_mausu)

--- date of update script 仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧仧
00:25 2018/06/11

]]
--track0:Length,0,1000,100,0.01
--track1:Angle,-1280,1280,135,0.01
--track2:AjustAlp,0,100,100,0.01
--track3:Alpha,0,255,255,1
--check0:Bidirectional,0;
--dialog:塭偺傒/chk,local isOnlyShadow=0;color/col,local shadowcol=0x747474;僌儔僨乕僔儑儞/chk,local isGrad=1;GradColor/col,local gradcol=0xdddddd;夞揮張棟/chk,local isChRotation=1;奼挘: 忋,local U=0;丂丂劋壓,local D=0;丂丂劋嵍,local le=0;丂丂劋塃,local R=0;

if rikky_module == nil then
	local CPATH = {}
	local cpath = package.cpath .. ";"
	local n
	while(1)do
		n = cpath:find(";")
		if n then
			CPATH[#CPATH + 1] = cpath:sub(1, n - 1)
			cpath = cpath:sub(n + 1, #cpath)
		else
			break
		end
	end
	if not CPATH[2]:find("script\\?.dll") then
		CPATH[3] = CPATH[2]:sub(1, CPATH[2]:find("\\script\\")) .. "script\\?.dll"
		package.cpath = package.cpath .. ";" .. CPATH[3]
	end
	for i = 1, #CPATH do
		local f = io.open(CPATH[i]:gsub("?", "rikky_module"), "rb")
		if f then
			require("rikky_module")
			f:close()
			break
		end
	end
end

if AviutlLongShadow == nil then
	local CPATH = {}
	local cpath = package.cpath .. ";"
	local n
	while(1)do
		n = cpath:find(";")
		if n then
			CPATH[#CPATH + 1] = cpath:sub(1, n - 1)
			cpath = cpath:sub(n + 1, #cpath)
		else
			break
		end
	end
	if not CPATH[2]:find("script\\?.dll") then
		CPATH[3] = CPATH[2]:sub(1, CPATH[2]:find("\\script\\")) .. "script\\?.dll"
		package.cpath = package.cpath .. ";" .. CPATH[3]
	end
	for i = 1, #CPATH do
		local f = io.open(CPATH[i]:gsub("?", "AviutlLongShadow"), "rb")
		if f then
			require("AviutlLongShadow")
			f:close()
			break
		end
	end
end


if rikky_module and AviutlLongShadow then
local w,h=obj.getpixel()
local L,ang=obj.track0,obj.track1-90-(obj.rz*isChRotation)
local fx,fy=
	L*math.cos(math.rad(ang)),
	L*math.sin(math.rad(ang))
local settmp=function() obj.setoption("dst","tmp") end
local t,px,py,x,y,p,i,j,k,t

if(fx<0)then
	le=-fx
else
	R=fx
end

if(fy<0)then	
	U=-fy	
else 
	D=fy
end

-- options
obj.alpha=isAdjAlpha==1 and obj.alpha*AdjAlpha/100 or obj.alpha
if isOnlyShadow==1 then obj.effect("扨怓壔","color",shadowcol,"婸搙傪曐帩偡傞",0) end
--if isGrad==1 then obj.setoption("dst","tmp") end

-- 椞堟奼挘&庢摼
if obj.check0 then 	obj.effect("椞堟奼挘","忋",U+D,"壓",U+D,"塃",R+le,"嵍",R+le)
else 					obj.effect("椞堟奼挘","忋",U,"壓",D,"塃",R,"嵍",le)			end
-- dll斉丅嶌惉偼偛嫵庼偄偨偩偄偨rikky巵偐傜丅
--[[
埲壓偼Lua偺傒丅
僾儔僌僀儞偑巊梡偱偒側偄応崌偵偍偄偰偺傒偛巊梡偔偩偝偄丅
傑偨丄巊梡偡傞嵺偼忋偺僾儔僌僀儞巊梡僐乕僪晹暘傪僐儊儞僩傾僂僩偟偰偔偩偝偄丅

for i =1,c do
	for j = 1,b[i] do
		x,y=
			a[i][j*2-1],
			a[i][j*2]
		for k = 0,L do

			p=k/L
			px,py=math.floor(x+fx*p),math.floor(y+fy*p)
			for v=0,3 do
				c,t=obj.getpixel(px+v%2,py+math.floor(v/2))
				if(t==0)then 
					-- settmp()
					obj.putpixel(px+v%2,py+math.floor(v/2),shadowcol,1) 
				end
			end
			-- c,t=obj.getpixel(px,py)
			-- if(t==0)then obj.putpixel(px,py,0xffffff,1) end
			-- c,t=obj.getpixel(px+1,py)
			-- if(t==0)then obj.putpixel(px+1,py,0xffffff,1) end
			-- c,t=obj.getpixel(px,py+1)
			-- if(t==0)then obj.putpixel(px,py+1,0xffffff,1) end
			-- c,t=obj.getpixel(px+1,py+1)
			-- if(t==0)then obj.putpixel(px+1,py+1,0xffffff,1) end
		end
	end
end
]]

--[[
if isGrad==1 then 
	obj.draw()
	obj.copybuffer("obj","tmp")
end
-- obj.load("tempbuffer")
-- obj.draw()
]]

local c

if isGrad==1 then
	obj.copybuffer("tmp","obj")
	c = AviutlLongShadow.func(L, ang, shadowcol, obj.track2, obj.track3, true)
	
	if obj.num>1 then
		obj.effect("僌儔僨乕僔儑儞","no_color",1,"color2",gradcol,"妏搙",ang-90,"暆",L)
	else
		if math.sin(math.rad(ang))<0 then
			obj.effect("僌儔僨乕僔儑儞","no_color",1,"color2",gradcol,"妏搙",180,"暆",L,"拞怱Y",-math.sin(math.rad(ang))*L/4)
		else
			obj.effect("僌儔僨乕僔儑儞","no_color",1,"color2",gradcol,"妏搙",0,"暆",L,"拞怱Y",-math.sin(math.rad(ang))*L/4)
		end
	end
	obj.draw()

	if obj.check0 then
		AviutlLongShadow.func(L, ang+180, shadowcol, obj.track2, obj.track3, true, c)
		if obj.num>1 then
			obj.effect("僌儔僨乕僔儑儞","no_color",1,"color2",gradcol,"妏搙",ang-90,"暆",L)
		else
			if math.sin(math.rad(ang))<0 then
				obj.effect("僌儔僨乕僔儑儞","no_color",1,"color2",gradcol,"妏搙",180,"暆",L,"拞怱Y",-math.sin(math.rad(ang))*L/4)
			else
				obj.effect("僌儔僨乕僔儑儞","no_color",1,"color2",gradcol,"妏搙",0,"暆",L,"拞怱Y",-math.sin(math.rad(ang))*L/4)
			end
		end
		obj.draw()
	end
	obj.copybuffer("obj","tmp")
	obj.draw()
else
	c = AviutlLongShadow.func(L, ang, shadowcol, obj.track2, obj.track3, isOnlyShadow==1)
	if obj.check0 then AviutlLongShadow.func(L, ang+180, shadowcol, obj.track2, obj.track3, isOnlyShadow==1, c) end
end
obj.setoption("antialias",1)
else
	obj.setfont("儊僀儕僆",25)
	local tx = "埲壓偺dll偑尒偮偐傝傑偣傫偱偟偨丅\ndll偺埵抲傗摫擖偝傟偰偄傞偐嵞搙妋擣偟偰偔偩偝偄:"
	if not rikky_module then tx = tx.."\nrikky_module.dll" end
	if not AviutlLongShadow then tx = tx.."\nAviutlLongShadow.dll" end
end