if GS_RAILS_SKINS==nil rawset(_G,"GS_RAILS_SKINS",{}) end --Make sure your own lump has this too!

local RAIL = GS_RAILS if RAIL and RAIL.blockload return end --Don't include this part in your own file

--X Sonic has multiple skins! https://mb.srb2.org/addons/x-sonic.7372/
for i = 1,2
	local NAME = (i==2) and "xsonicserious" or "xsonic"
	if (GS_RAILS_SKINS[NAME]!=nil) continue end --
	
	GS_RAILS_SKINS[NAME] = {} local SKIN = GS_RAILS_SKINS[NAME]
	
	SKIN["S_SKIN"] = {
	SIDEHOP = (i==2) and 46 or 37,
	SIDEHOPARC = 20-i,
	SIDEHOPTIME = (i==2) and 9 or 11,
	SIDEFLIP = SPR2_FALL, --We all know this is what Blur would want	
	AIRDRAG = (i==1) and 60 or 20,
	CROUCH = true,
	CROUCHBUTTON = BT_CUSTOM1|BT_SPIN,
	AUTOBALANCE = false,
	EMERGENCYDROP = false, --Gets in the way of Super Sonic.
	
	STARTMODIFIER = (i==2) and 20 or -20,
	STARTSPEEDCONDITION = 76-i,
	
	MAXSPEED = (i==2) and 260 or 230,
	
	HEROESTWIST = (i==2) and 33 or 27, --He did sort of do this in Sonic X!
	TWISTBUTTON = BT_CUSTOM2|BT_CUSTOM1|BT_SPIN,
	NOFUNALLOWED = (i==2) and true or false,
	WALLCLINGSPRITE = SPR2_SKID,
	}
	
	SKIN["GrindThinker"] = function(p, s, GS, rail)
		local xs = p.xsonictable
		if xs
			xs.ziptrailticket = nil
			xs.framejump,xs.squatcharge,xs.fallbuffer,xs.squat = 0,0,0
			if (GS.grinding < 8) and (p.cmd.buttons & BT_SPIN)
				GS.spinstate = true
			end
			if not GS.speedtrail and rail
				local CONVEYOR = rail.GSconveyor and rail.GSconveyor<<16 or 0
				if (abs((GS.railspeed or 0)+CONVEYOR)> 87*s.scale)
					GS.speedtrail = 2
				end
			end
		end
	end
	
	SKIN["PlayerThink"] = function(p,s,GS,rail)
		if p.xsonictable
			local xs = p.xsonictable
			if GS.grinding
				xs.custom3 = 999<<16
				local STATS = GS_RAILS_SKINS[s.skin]
				if STATS
					if STATS.WALLCLINGSPRITE==SPR2_SKID
						STATS.WALLCLINGSPRITE = SPR2_WLRN
						if (RAIL.NeverAttachTypes)
							RAIL.NeverAttachTypes[MT_XSLAMBENTHB] = true
							RAIL.NeverAttachTypes[MT_XSSNAPDIVE] = true
							RAIL.NeverAttachTypes[MT_XSASSAULTHB] = true
						end
					end
				end
			elseif GS.JumpRamp or GS.leftrail or ((GS.railswitching or 0) > 6)
				xs.jump,xs.spin = 999<<16,999<<16
				xs.tossflag,xs.custom1,xs.custom2,xs.custom3 = 999<<16,999<<16,999<<16, 999<<16
				if ((GS.FrontiersLeap or 0) > 8)
					xs.diveslowdown,xs.ringburstcd = 0,0
					if (p.panim==PA_ROLL or p.panim==PA_JUMP) and (p.pflags & (PF_JUMPED|PF_NOJUMPDAMAGE))
						s.state = S_PLAY_XDIVEFLIP1
						s.tics,s.anim_duration = $*2,$*2
					end
				elseif GS.leftrail or GS.JumpRamp
					xs.ringburstcd = max(xs.ringburstcd or 0,1)	
					if ((xs.zipdash or 0)<4) and (p.cmd.buttons & (BT_SPIN|BT_CUSTOM1)) and not GS.JumpRamp
						if GS.leftrail and (p.speed > 41*s.scale) and not GS.railswitching 
						and not (p.cmd.buttons & BT_JUMP) and ((p.panim>=PA_IDLE) and (p.panim<=PA_DASH))
						and not (p.pflags & (PF_STARTJUMP|PF_SLIDING|PF_SPINNING))
							S_StopSoundByID(s, sfx_xssfxa)
							xs.zipdashslide,xs.zipspam,xs.delayzip,xs.justleaped,xs.zipcd = 0,0,0,0,0
							xs.zipdash = 6
							xs.zipcontinue = true						
							xs.spin = 2
						end
					end
				end
			end
		end
	end
	
	SKIN["CustomJump"] = function(p, s, GS, rail, RAMPJUMP)
		local xs = p.xsonictable
		if xs
			xs.jumpboost = 0
			xs.didjumpboost = true
			xs.zipleapbuffer = 0
			if rail and GS.railspeed
				local CONVEYOR = rail.GSconveyor and rail.GSconveyor<<16 or 0
				if (abs((GS.railspeed or 0)+CONVEYOR) > 76*s.scale)
				and not ((xs.darkphase or 0)>=2) and not p.powers[pw_super] and not p.powers[pw_sneakers]
					GS.railspeed = FixedDiv(FixedMul($, 9), 10)
				end
			end
		end
	end
	
	if i==1
		SKIN["PreAttach"] = function(p, so, GS, mainrail, s)
			if p and p.xsonictable and p.xsonictable.FreeFlight and p.powers[pw_super]
				return true --
			end
		end
	end
	
	SKIN["PostExit"] = function(p, s, GS, rail, sameXY, SLOPEFLING, JUMPRAMP)
		local xs = p.xsonictable
		if xs
			xs.jump,xs.spin = 999<<16,999<<16
			xs.tossflag,xs.custom1,xs.custom2,xs.custom3 = 999<<16,999<<16,999<<16, 999<<16
			xs.ringburstcd = max(xs.ringburstcd or 0, 2)
		end
	end
	
	SKIN["FinalThinker"] = function(p, s, GS)
		if (s.XS_soaps) --Sync up, pls.
			for i = 6,4,-1
				local ghs = s.XS_soaps[i]
				if ghs and ghs.valid
					if GS.grinding and not (GS.flipanim)
						ghs.frame = ($&~FF_VERTICALFLIP)|(s.frame&FF_VERTICALFLIP)
						if (leveltime%3==0)
							ghs.rollangle = s.rollangle
						end
						ghs.mirrored = s.mirrored
						ghs.angle = p.drawangle
						ghs.spritexoffset,ghs.spriteyoffset = s.spritexoffset,s.spriteyoffset
						P_MoveOrigin(ghs, s.x, s.y, s.z)
					elseif ghs.fuse
						ghs.sttfade = true
						ghs.fuse = min($, 4)
					end
				end
			end
		end
	end		
end