Path: blob/main/Scripts/Special/HWBackG_S6.txt
1319 views
//---------------Sonic CD HW Background Script----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.Timer67// These pair of values correspond to X coordinates on the sprite sheet8#alias Object.Value1 : Object.SpriteL9#alias Object.Value2 : Object.SpriteR1011// These pair of values correspond to Y coodinates on the sprite sheet12// Value4 - SpriteB - is unused13#alias Object.Value3 : Object.SpriteT14#alias Object.Value4 : Object.SpriteB1516// Used to determine the base X position for the background17#alias Object.Value5 : Object.Angle1819// Between the initial game release and the latest mobile update, the offset for the background got changed20// Originally it was 64, but 48's what's used nowadays21// (Origins uses 48 too, so that's how we know it's truly an update change and not a HW renderer change)2223#alias 48 : HWBACK_XOFFSET2425// Priority26#alias 1 : PRIORITY_ACTIVE2728// Face Buffer Flags29#alias 1 : FACE_FLAG_TEXTURED_2D303132sub ObjectDraw33Object.Timer++34if Object.Timer > 335Object.Timer = 03637Object.Frame++38Object.Frame %= 123940// Setup the new sprite bounds4142// First, get the left bounds of the sprite43Object.SpriteL = Object.Frame44Object.SpriteL &= 345Object.SpriteL <<= 74647// And then, the right bounds is just 127 pixels ot the left of that48Object.SpriteR = Object.SpriteL49Object.SpriteR += 1275051// After that, comes the top bounds52Object.SpriteT = Object.Frame53Object.SpriteT >>= 254Object.SpriteT <<= 75556// And similarly, the bottom bounds is just 127 pixels down from the top57Object.SpriteB = Object.SpriteT58Object.SpriteB += 12759end if6061// Update the Angle for the background62Object.Angle += 263Object.Angle &= 5116465// Order of Values here:66// - TempValue0 is just a general loop counter67// - TempValue4 is the angle, it gets shifted a bit after every loop68// - TempValue1 is the upper Y mapping for the sprite, this gets changed a bit throughout69// - TempValue2 is the lower Y mapping for the sprite, this gets changed a bit throughout as well70// - ArrayPos0 is the index of the VertexBuffer to change7172TempValue0 = 073TempValue4 = Object.Angle74TempValue1 = Object.SpriteT75TempValue2 = Object.SpriteB76ArrayPos0 = 07778while TempValue0 < 167980// Get the base X change value81Sin(TempValue3, TempValue4)8283// Adjust the change value as needed to get what we want84TempValue3 /= 1285TempValue3 -= HWBACK_XOFFSET8687// Change the angle a bit so that future loops look different88TempValue4 += 5689TempValue4 &= 5119091// And now, let's actually change those vertexes!9293// ArrayPos0 + 0 - top left of a face + 094VertexBuffer[ArrayPos0].u = Object.SpriteL95VertexBuffer[ArrayPos0].v = TempValue196VertexBuffer[ArrayPos0].x = TempValue397ArrayPos0++9899TempValue3 += 128100101// ArrayPos0 + 1 - top right of a face + 0102VertexBuffer[ArrayPos0].u = Object.SpriteR103VertexBuffer[ArrayPos0].v = TempValue1104VertexBuffer[ArrayPos0].x = TempValue3105ArrayPos0 += 3106107// ArrayPos0 + 4 - top left of a face + 1108VertexBuffer[ArrayPos0].u = Object.SpriteR109VertexBuffer[ArrayPos0].v = TempValue2110VertexBuffer[ArrayPos0].x = TempValue3111ArrayPos0++112113TempValue3 += 128114115// ArrayPos0 + 5 - top right of a face + 1116VertexBuffer[ArrayPos0].u = Object.SpriteL117VertexBuffer[ArrayPos0].v = TempValue2118VertexBuffer[ArrayPos0].x = TempValue3119ArrayPos0 += 3120121// ArrayPos0 + 8 - top left of a face + 2122VertexBuffer[ArrayPos0].u = Object.SpriteL123VertexBuffer[ArrayPos0].v = TempValue1124VertexBuffer[ArrayPos0].x = TempValue3125ArrayPos0++126127TempValue3 += 128128129// ArrayPos0 + 9 - top right of a face + 2130VertexBuffer[ArrayPos0].u = Object.SpriteR131VertexBuffer[ArrayPos0].v = TempValue1132VertexBuffer[ArrayPos0].x = TempValue3133ArrayPos0 += 3134135// ArrayPos0 + 12 - top left of a face + 3136VertexBuffer[ArrayPos0].u = Object.SpriteR137VertexBuffer[ArrayPos0].v = TempValue2138VertexBuffer[ArrayPos0].x = TempValue3139ArrayPos0++140141TempValue3 += 128142143// ArrayPos0 + 13 - top right of a face + 3144VertexBuffer[ArrayPos0].u = Object.SpriteL145VertexBuffer[ArrayPos0].v = TempValue2146VertexBuffer[ArrayPos0].x = TempValue3147148// Move to the lower half vertexes149ArrayPos0 -= 11150151TempValue1 += 8152TempValue2 -= 8153154// Get the new X change value155Sin(TempValue3, TempValue4)156157TempValue3 /= 12158TempValue3 -= HWBACK_XOFFSET159160// ArrayPos0 + 2 - bottom left of face + 0161VertexBuffer[ArrayPos0].u = Object.SpriteL162VertexBuffer[ArrayPos0].v = TempValue1163VertexBuffer[ArrayPos0].x = TempValue3164ArrayPos0++165166TempValue3 += 128167168// ArrayPos0 + 3 - bottom right of face + 0169VertexBuffer[ArrayPos0].u = Object.SpriteR170VertexBuffer[ArrayPos0].v = TempValue1171VertexBuffer[ArrayPos0].x = TempValue3172ArrayPos0 += 3173174// ArrayPos0 + 6 - bottom left of face + 1175VertexBuffer[ArrayPos0].u = Object.SpriteR176VertexBuffer[ArrayPos0].v = TempValue2177VertexBuffer[ArrayPos0].x = TempValue3178ArrayPos0++179180// ArrayPos0 + 7 - bottom right of face + 1181TempValue3 += 128182VertexBuffer[ArrayPos0].u = Object.SpriteL183VertexBuffer[ArrayPos0].v = TempValue2184VertexBuffer[ArrayPos0].x = TempValue3185ArrayPos0 += 3186187// ArrayPos0 + 10 - bottom left of face + 2188VertexBuffer[ArrayPos0].u = Object.SpriteL189VertexBuffer[ArrayPos0].v = TempValue1190VertexBuffer[ArrayPos0].x = TempValue3191ArrayPos0++192193TempValue3 += 128194195// ArrayPos0 + 11 - bottom right of face + 2196VertexBuffer[ArrayPos0].u = Object.SpriteR197VertexBuffer[ArrayPos0].v = TempValue1198VertexBuffer[ArrayPos0].x = TempValue3199ArrayPos0 += 3200201// ArrayPos0 + 14 - bottom left of face + 3202VertexBuffer[ArrayPos0].u = Object.SpriteR203VertexBuffer[ArrayPos0].v = TempValue2204VertexBuffer[ArrayPos0].x = TempValue3205ArrayPos0++206207TempValue3 += 128208209// ArrayPos0 + 15 - bottom left of face + 3210VertexBuffer[ArrayPos0].u = Object.SpriteL211VertexBuffer[ArrayPos0].v = TempValue2212VertexBuffer[ArrayPos0].x = TempValue3213ArrayPos0++214215TempValue0++216loop217218// Wow, that's quite the total!2193DScene.NoVertices = 2562203DScene.NoFaces = 64221222// Now, draw all the 3d stuff we just set up223Draw3DScene()224225// After that, draw a few purple boxes underneath, where the 3d stuff didn't reach226DrawSpriteScreenXY(0, 0, 0)227DrawSpriteScreenXY(0, 256, 0)228229end sub230231232sub ObjectStartup233234// This Object should only exist if the game is using the Hardware Renderer,235// as the Software Renderer doesn't need this236#platform: HW_Rendering237238// Purple rectangle background Frame239SpriteFrame(0, 128, 256, 128, 256, 384)240241// Reset all the 3d stuff242MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)243MatrixTranslateXYZ(MAT_VIEW, 0, 0, 0)244245// Disable the stage background, in favour of what's gonna be done by this Object246Stage[0].ActiveLayer = 9247248// Load the Sprite Sheet for the Object249// Yeah, the Sprite Frames were set up before the Sprite Sheet itself was even loaded...250LoadSpriteSheet("Special/SSBG6.gif")251252// Place a HW Background object into the last of the Reserved Object Slots253Object[31].Type = TypeName[HW Background]254255// Make it always active, and since it's to be a background, give it the Draw Order of such accordingly256Object[31].Priority = PRIORITY_ACTIVE257Object[31].DrawOrder = 0258259// Make its initial Sprite values be the first, top left frame260Object[31].SpriteL = 0261Object[31].SpriteR = 128262Object[31].SpriteT = 0263Object[31].SpriteB = 128264265// Setup all the faces266ArrayPos0 = 0267TempValue0 = 0268while ArrayPos0 < 64269270// Set the face's corners to their corresponding Vertexes271FaceBuffer[ArrayPos0].a = TempValue0272TempValue0++273FaceBuffer[ArrayPos0].b = TempValue0274TempValue0++275FaceBuffer[ArrayPos0].c = TempValue0276TempValue0++277FaceBuffer[ArrayPos0].d = TempValue0278TempValue0++279280FaceBuffer[ArrayPos0].Flag = FACE_FLAG_TEXTURED_2D281282// And onto the next face!283ArrayPos0++284285loop286287// Make all Vertexes have a depth of 1288// This doesn't really matter much, though, as they all belond to a 2D vertex anyway, where depth isn't used289ArrayPos0 = 0290while ArrayPos0 < 256291VertexBuffer[ArrayPos0].z = 1292ArrayPos0++293loop294295// Set the Y values for all the vertexes296TempValue0 = 0297ArrayPos0 = 0298while TempValue0 < 128299300// First, do all the upper vertexes301302// First face303VertexBuffer[ArrayPos0].y = TempValue0304ArrayPos0++305VertexBuffer[ArrayPos0].y = TempValue0306ArrayPos0 += 3307308// Second face309VertexBuffer[ArrayPos0].y = TempValue0310ArrayPos0++311VertexBuffer[ArrayPos0].y = TempValue0312ArrayPos0 += 3313314// Third face315VertexBuffer[ArrayPos0].y = TempValue0316ArrayPos0++317VertexBuffer[ArrayPos0].y = TempValue0318ArrayPos0 += 3319320// Fourth face321VertexBuffer[ArrayPos0].y = TempValue0322ArrayPos0++323VertexBuffer[ArrayPos0].y = TempValue0324325// Now, go back to the bottom half vertexes326ArrayPos0 -= 11327328TempValue0 += 8329330// First face331VertexBuffer[ArrayPos0].y = TempValue0332ArrayPos0++333VertexBuffer[ArrayPos0].y = TempValue0334ArrayPos0 += 3335336// Second face337VertexBuffer[ArrayPos0].y = TempValue0338ArrayPos0++339VertexBuffer[ArrayPos0].y = TempValue0340ArrayPos0 += 3341342// Third face343VertexBuffer[ArrayPos0].y = TempValue0344ArrayPos0++345VertexBuffer[ArrayPos0].y = TempValue0346ArrayPos0 += 3347348// Fourth face349VertexBuffer[ArrayPos0].y = TempValue0350ArrayPos0++351VertexBuffer[ArrayPos0].y = TempValue0352ArrayPos0++353loop354#endplatform355356end sub357358359// ========================360// Editor Subs361// ========================362363sub RSDKDraw364DrawSprite(0)365end sub366367368sub RSDKLoad369LoadSpriteSheet("Special/SSBG6.gif")370SpriteFrame(-32, -32, 64, 64, 1, 143)371372SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")373end sub374375376