Skip to content

Instantly share code, notes, and snippets.

@RomanHargrave
Last active December 14, 2020 00:39
Show Gist options
  • Save RomanHargrave/ec12a201ec4754027b8934e94f4c2ace to your computer and use it in GitHub Desktop.
Save RomanHargrave/ec12a201ec4754027b8934e94f4c2ace to your computer and use it in GitHub Desktop.

AudioSurf 2 Lua Documentation

This is reverse-engineered from the game.

Scene manager functions

These functions are registered when LuaController.Start() is called. These are used by skins.

print(obj) : nil

Write object/text to the debug console for skins.

Implementation

// public class LuaManager
public void write(object o)
{
    string text = null;
    if (o != null)
    {
        text = ((o is string) ? ((string)o) : ((!(o is LuaTable)) ? o.ToString() : LuaX.TableToString_Recursive((LuaTable)o)));
    }
    Messenger<string>.Broadcast("LuaSkinPrintText", text);
    if (!Application.isEditor)
    {
        UnityEngine.Debug.Log("Lua Skin:" + text);
    }
}

PlayerCanJump() : bool

Can the player jump?

Implementation

// public class SceneManager
public bool PlayerCanJump()
{
    return CharacterManager.Instance.canJump;
}

SetPlayer(tbl) : nil

Set player attributes, mostly related to appearance and camera. tbl is a table containing any of the following

  • fov = 90.0 - Field of view
  • cameraortho = false - Orthographic camera?
  • cameraignoreslope = false - ???
  • cameraHeightTrackingRatio = 1.0 - Camera height tracking ratio
  • cameramode - String describing camera mode
    • cameramode = "first" - First-person camera mode
    • cameramode = "third" - Third-person camera mode
    • cameramode = "first_jumpthird" - First-person camera, but third-person when jumping
    • cameramode = "first_trickthird" - First-person camera, but third-person when performing a trick
    • cameramode = "first_trickjumpthird" - First preson camera, but third-person when jumping or performing a trick
  • cameradynamics - Camera dynamics
    • cameradynamics = "high" - Use extra camera dynamics
    • cameradynamics = "..." (Anything but "high") - Do not use extra camera dynamics
  • camfirst = { ... } - First-person camera properties table
    • .pos = {x, y, z} - Camera position
    • .rot = {rX, rY, rZ} - Camera rotation (does not apply in VR mode)
    • .strafefactor = 1.0 - Strafe factor (does not apply in VR mode)
    • .puzzleoffset - Ring offset (if puzzle renderer present)
  • camthird = { ... } - Third-person camera properties table
    • .pos = {x, y, z} - Camera position
    • .rot = {rX, rY, rZ} - Camera rotation (does not apply in VR mode)
    • .strafefactor = 0.5 - Camera strafe factor (does not apply in VR mode)
    • .pos2 = {x, y, z} - Near position
    • .rot2 = {rX, rY, rZ} - Near rotation (only if camthird.pos2 is present, does not apply in VR mode)
    • .strafefactorFar = 1.0 - Far strafe factor (only if camthird.pos2 is present, does not apply in VR mode)
    • .transitionspeed = 1.0 - Transition speed between camera perspectives
    • .puzzleoffset - Close ring offset (if puzzle renderer present)
    • .puzzleoffset2 - Far ring offset (if puzzle renderer present)
  • vehicle - Vehicle parameters
    • .reflect = false - Enable vehicle reflector (mirroring?)
    • .min_hover_height = 0.0 - Minimum hover height
    • .max_hover_height = 0.0 - Maximum hover height
    • .use_water_rooster = true - Boat????
    • .rollscaler = -1.0 - ???
    • .smooth_tilting = false - Smooth tilting
    • .smooth_tilting_speed = 10.0 - Smooth tilting speed
    • .smooth_tilting_max_offset = -20.0
    • .water_rooster_z_offset = -1.04
    • .roostercolor = {0.133, 0.22, 0.486, 1.0}
    • .airvehicle = {<GameObject>}
    • .watervehicle = {<GameObject>}
    • .surfer
      • .use_water_rooser = true
      • .roosercolor = {0.133, 0.22, 0.486, 1.0}
      • .arms = {<GameObject>}
      • .leg = {<GameObject>}
      • .body = {<GameObject>}
      • .board = {<GameObject>}
      • .towrope_node = {<GameObject>}
      • .towboat = {<GameObject>}

Profile(name = "...") : nil

Print time since last call. name is used only for debug, and has no effect on metrics.

GetTrack() : {<Highway>}

Get the track.

GetIntensity() : real

Get current intensity

GetSpectrum() : {...}

Get FFT16 at instant

UpdateSpectrum({...}) : {...}

Update FFT16

UpdateSpectrum512({...}) : {...}

Update FFT512

GetLogSpectrum() : {...}

Get FFT16 (logarithmic)

BuildMesh(params = {<MeshParams>}) : real

Build mesh (will document shape and purpose later)

CreateRail(params = {<RailParams}) : nil

Create a rail

CreateRailedObject(params = {ObjectParams}) : nil

Create an object

SetSkybox(params = {...}) : nil

Set the level skybox. params contains an enourmous quantity of fields.

SetRings(params = {...}) : nil

Set rings, params may contain the following

  • shadowcaster = false - Rings cast shadows?
  • shadoreceiver = false - Rings receive shadows?
  • layer = 11 - Layer
  • offset = <real> - Offset
  • size = 0.0 - Size
  • percentringed = 0.0
  • useairrings = true
  • material = {<Material>}
  • airsize = 0.0
  • airmaterial = {<Material>}

SetWake(params = {...}) : nil

Set wake props, params may contain the following

  • height = 0.0
  • fallrate = 0.0
  • layer = 11
  • material = {<Material>}
  • offsets = {{x, y, z}...}
  • bottomcolor = "..." | {r, g, b, a}
    • bottomcolor = "highway"
    • bottomcolor = "highwayinverted"
  • topcolor = "..." | {r, g, b, a} - See bottomcolor
  • extraspray = false

Mod functions

Mode/mod functions

GameplaySettings(settings = {...}) : nil

Set gameplay params. settings contains

  • jumpheightscaler = 1.0
  • gravity = -0.45
  • allowmusicdroponfail = false
  • preventautomaticoverfillclear = false
  • usetraffic = true
  • airstrafing = false
  • usejumpmarkers = false
  • fullgrid_collectiongracetime = 0.0
  • smoothstrafetowake = false
  • puzzleblockfallinterval = 0.1
  • blockflight_secondstopuzzle = 0.35
  • calculate_antijumps_and_antitraffic = false
  • automatic_traffic_collisions = true
  • usepuzzlegrid = true - Mode uses puzzle grid
  • puzzlerows = 7 - Number of rows in puzzle grid
  • puzzlecols = 3 - Number of columns in puzzle grid
  • cleargridonlanding = true - Clear the grid on landing after trick?
  • forceclearingsinglecolumns = true
  • forcecollectionoverfill = true
  • show_x_in_a_row_text = false
  • useBlockTrailToOptimalJumps = false
  • removeBlocksNearOptimalJumps = 0
  • usePinatas = false
  • useAirBlocks = false
  • blocksInLanes = true
  • useLivingScoreboardGhosts = true
  • cancrash = true|false - Can tricks fail?
  • canpush - Can push?
  • canScoop - Can collect blocks for use later?
  • blocktype_grey = 5
  • blocktype_highway = 6
  • blocktype_highwayinverted = 7
  • rightsticksteering = false - Steer with right stick (gamepad)
  • minvisibletrafficblocks = 0
  • greypercent = 0.3 - Percent of blocks that are greys (spikes)
  • greyrandomdistribution = false - Use a random distribution for greys
  • usecaterpillars = bool - Use caterpillars?
  • minimummultiplier = real
  • jumpautofixscaler = real
  • sideview = false - Side scroller?
  • minstrafespeedforwakejump = real - Minimum strafe speed to go into jump
  • degreyatlandingzone = bool - Remove greys in zone after landing from jump
  • launchtrickmultiplier = real
  • maxnumtricksperjump = int
  • autofinishgamepadjumps = bool
  • autofinishmousejumps = bool
  • puzzlematchmultiplier = real
  • stealthscoremultiplier = real
  • secondstoblockjumpsafterlanding = real
  • easytraffic = bool
  • autostartlaunchtricksforheldbuttons = true
  • jumpmode = "..." - Jump mode
    • "none" - Disable jumping
    • "manual"
    • "ramps"
    • "button"
    • "wake"
    • "wake_or_button"
    • "button_press"
    • "auto"
  • minimumjump_airtime = real
  • minimumjump_height = real
  • startingscore = 0
  • pointspergrey = int
  • pointspercolor = int
  • matchcollectionseconds = 1.5
  • minmatchsizes = {<int>...}
  • greyaction = "..."
    • "clog" | "stuck" | "permanent" - Stays in grid
    • "eraseone" | "erasesingle" | "eraseblock" - Remove nearest block from grid
    • "erasecolumn" - Remove nearest column from grid
    • "erasegrid" | "eraseall" - Remove all blocks from grid
  • usetrickscorewindow = true
  • trickdurations = {<real>...}
  • trickpoints = {<real>...}
  • playerminspeed = real
  • playermaxspeed = real
  • minimumbestjumptime = real
  • uphilltiltscaler = real
  • downhilltiltscaler = real
  • uphilltiltsmoother = real
  • downhilltiltsmoother = real
  • useadvancedsteepalgorithm = true
  • alldownhill = false
  • railedblockscanbegrey = false
  • trafficcompression = bool
  • watercompression = bool
  • autocenter = bool
  • maxstrafe = real
  • usesnowboardphysics = bool
  • freqtrafficbins = 256 - (must be at least 256)
  • freqtrafficbins_logspaced = false

SetRenderViewports(ports = {...}) : nil

Set visualizer viewports. ports is a table of tables, where each table a viewport. A viewport table has the following fields:

  • pos = {x, y, z} - Position
  • rot = {rX, rY, rZ} - Rotation
  • scale = {mX, mY, mZ} - Scale

print(object)

Print object to the unity debug log.

GetPuzzle() : {<Puzzle>}

Get the puzzle.

GetTrickMultiplier() : real

Get the trick multiplier

BatchRenderEveryFrame(renderers = {{<BatchRenderEveryFrame>}...}) : nil

Things to render?

BatchRender(stuff = {...}) : nil

Render things?

UpdateBatchRenderer(renderer = {<BatchRenderEveryFrame>}) : nil

Update a batch renderer

GetCurrentTrackLocation() : real

Get current track location

GetCurrentTrackWorldPosition() : {<Pos>}

Get current track world position.

CreateClone(table = {...}) : nil

Create clones of things???

SendCommand(cmd = {...}) : nil

Interface with the event system.

Logic:

  • If cmd.name is set
    • Then, if cmd.name is a clone,
      • Then, if cmd.command is a string,
        • Then, if cmd.param is a table
          • Then, call one of SetParent, ChangeShaderColors, SetTransform, Blink, ChangeTrackNodeOffset, ChangeTrafficBlockConeType based on cmd.command with cmd.param as the arguments on the clone corresponding to cmd.name
          • Otherwise, broadcast cmd.command to the clone corresponding to cmd.name
    • Otherwise, print a warning to the Unity debug log

SendCommands(cmds = {{...}...}) : nil

Call SendCommand(cmd) on each table in cmds

GetInput() : {<InputState>}

Get input state.

SetLocalScore(params = {...}) : nil

Set local score.

params is

  • name = "nameless" - Competitor name
  • score = 0.0 - Competitor score
  • displayScore = string - Competitor display score

SetGlobalScore(params = {...}) : nil

Set global score. Achieved by broadcasting SetScoreFromMod(int, bool, Color).

params is

  • score = 0 - Score
  • showdelta = true - Show change
  • deltacolor = Color.white - Color to show change in

PlayBuiltInSound(sound = {...}) : nil

Play a sound.

sound is

  • soundType = "none" - Sound to play
  • avatar = "na" - If playing "grunt", this is the avatar that will play it

GetJumpHeights(params = {...}) : {<real>...}

Returns a table of real with ring jump heights

params is

  • launchNode = int

SetPuzzle(params = {...}) : nil

Set puzzle params. params may contain the following fields. Note that params is not a {<Puzzle>}

  • trackoffset = real
  • timing = {...}
    • .addallinflightblocksnow = any - Presence of this key causes all blocks to land
    • .matchtimer = real - Time til match is cleared
    • .matchtimerthreshold = real
    • .collectnow_usingmultiplier = real - Collect points from match using given multiplier NOW
    • .colectioncanautoplaysounds = true - Can auto-play sounds when forcing collect with multiplier?
  • newblocks = {...} - Blocks to add
    • #n - A block to add
      • .type = 0 - Block type
      • .collision_strafe = 0.0
      • .add_top = false
      • .transitionseconds = real
      • .powerupname = string . .shrinkdown = true
  • cells = {...}
    • #n - Column n, value is array of tables
      • #n - Row n in column, value is table
        • .type = -1 - Color ID
  • flyups = {...}
    • #n
      • .row = 0 - Row
      • .col = 0 - Column
      • .type = 0 - Color ID

HideBuiltinPlayerObjects() : nil

Hide the surfer, vehicle, and rooster.

SetCamera(params = {...}) : nil

Set camera params.

Implementation

// class LuaMods
public void SetCamera(LuaTable table)
{
	object obj = table["cameraortho"];
	if (obj is bool)
	{
		SkinManager.useOrthographicCameras = (bool)obj;
	}
	obj = table["pos"];
	if (obj is LuaTable)
	{
		SkinManager.useModForcedCamera = true;
		SkinManager.modForcedPos = LuaX.OToVector3(table["pos"], Vector3.zero);
		SkinManager.modForcedRot = LuaX.OToVector3(table["rot"], Vector3.zero);
		if (LuaX.TryReadVector3(table["parentrot"], ref SkinManager.modForcedParentRot))
		{
			SkinManager.useModForcedCameraParentRot = true;
		}
		LuaValue value = table.GetValue("railoffset");
		switch (value.Type)
		{
		case LuaType.String:
			if ((string)value == "detached")
			{
				SkinManager.attachCameraToTrack = false;
			}
			break;
		case LuaType.Number:
			SkinManager.cameraTrackOffset = (float)value;
			break;
		}
	}
	else
	{
		LuaTable luaTable = table["nearcam"] as LuaTable;
		if (luaTable != null)
		{
			SkinManager.firstPersonPos = LuaX.OToVector3(luaTable["pos"], Vector3.zero);
			SkinManager.ThirdPersonNearPos = LuaX.OToVector3(luaTable["pos"], Vector3.zero);
			SkinManager.firstPersonRot = LuaX.OToVector3(luaTable["rot"], Vector3.zero);
			SkinManager.ThirdPersonNearRot = LuaX.OToVector3(luaTable["rot"], Vector3.zero);
			SkinManager.thirdPersonNearStrafeFactor = luaTable.GetValue("strafiness").OrDefault(0f);
		}
		luaTable = (table["farcam"] as LuaTable);
		if (luaTable != null)
		{
			SkinManager.ThirdPersonFarPos = LuaX.OToVector3(luaTable["pos"], Vector3.zero);
			SkinManager.ThirdPersonFarRot = LuaX.OToVector3(luaTable["rot"], Vector3.zero);
			SkinManager.thirdPersonFarStrafeFactor = luaTable.GetValue("strafiness").OrDefault(0f);
		}
	}
	table.Dispose();
}

HideTraffic(blocks = {<int>...}) : nil

Hide the given blocks.

SetSkinProperties(props = {<SkinProperties>}) : nil

Set skin properties.

GetQualityLevel() : int

Get quality level

SetScoreboardNote(details = {...}) : nil

Set scoreboard note.

details is

  • secondsvisible = 0 - Visibility duration
  • color = {195, 195, 195, 255} - Note color
  • text = "" - Note text

DoJump() : nil

Jump now.

ChangeTraffic(params = {...}) : nil

Mess with traffic.

Implementation

public void ChangeTraffic(LuaTable table)
{
	List<TrafficManager.BlockModifier> changes = new List<TrafficManager.BlockModifier>();
	table.ForEachV(delegate(LuaValue key, object value)
	{
		LuaTable luaTable = value as LuaTable;
		if (!(luaTable == null))
		{
			LuaTable luaTable2 = luaTable;
			try
			{
				TrafficManager.BlockModifier item = default(TrafficManager.BlockModifier);
				LuaValue value2 = luaTable.GetValue("index");
				if (value2.Type != 0)
				{
					item.index = value2.OrDefault(1) - 1;
					item.powerupName = luaTable.GetValue("powerupname").AsString;
					LuaValue value3 = luaTable.GetValue("type");
					if (value3.Type != 0)
					{
						item.type = value3.OrDefault(1);
					}
					item.vOffset = luaTable.GetVector3("v3offset");
					changes.Add(item);
				}
			}
			finally
			{
				if (luaTable2 != null)
				{
					((IDisposable)luaTable2).Dispose();
				}
			}
		}
	});
	Messenger<List<TrafficManager.BlockModifier>>.Broadcast("ChangeBlocks", changes, MessengerMode.DONT_REQUIRE_LISTENER);
	table.Dispose();
}

SetBlockColors(params = {...}) : nil

Change block colors

Implementation

public void SetBlockColors(LuaTable table)
{
	Color[] array = LuaX.TableToColors(table);
	bool flag = false;
	if (array.Length != GlobalColors.blockColors.Length)
	{
		flag = true;
	}
	if (!flag)
	{
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] != GlobalColors.blockColors[i])
			{
				flag = true;
				break;
			}
		}
	}
	if (flag)
	{
		GlobalColors.SetBlockColors(array);
	}
}

GetBlockColors() : {...}

Get block colors.

Table shape {<Pos>}

  • x or 1 - X coordinate
  • y or 2 - Y coordinate
  • z or 3 - Z coordinate

Table shape {<InputState>}

  • mouse
    • .x - Mouse X delta
    • .y - Mouse Y delta
    • .LMB - Mouse button 0 (X11 numbering) state
    • .MMB - Mouse button 1 (X11 numbering) state
    • .RMB - Mouse button 2 (X11 numbering) state
    • .wheel - Mouse wheel delta
  • keyboard
    • .a ... .z - Key states
    • .'0' ... .'9' - Key states
    • .uparrow - Key states
    • .downarrow - Key states
    • .leftarrow - Key states
    • .rightarrow - Key states
    • .semicolon - Key states
    • .comma - Key states
    • .period - Key states
    • .space - Key states
    • .anykey - Is any key pressed?
    • .nokey - Are no keys pressed?
  • activedevice - active input device (single player?)
    • .Horizontal - Left stick X
    • .Vertical - Left stick Y
    • .Horizontal2 - Right stick X
    • .Vertical2 - Right stick Y
    • .button1 ... .button4 - Button states
    • .LeftBumper - Left bumper state
    • .RightBumper - Right bumper state
    • .LeftTrigger - Left trigger value
    • .RightTrigger - Right trigger value
    • .name - Device name
  • players - Player devices
    • .1 ... .4 - Devices, shape is identical to activedevice

Table shape {<Puzzle>}

  • cells
  • #n - Column n in puzzle
  • #n - Row n in column
  • type - Cell color ID
  • matched - Cell is matched?
  • matchsize - Number of other cells in the match
  • matccols - Number of columns in the match
  • matchedcellscount - Number of matched cells in grid overall
  • pendingblockcounts
  • #n - Pending blocks for column n

Table shape {<SkinProperties>}

  • lanedividers = {{1.0, -1.5}, {2.0, 1.5}}
  • shoulderlines = {{1.0, 4.5}, {2.0, -4.5}}
  • trackwidth = 11.6
  • prefersteep = false

Object shapes

Game object (GameObject)

A table, with the following fields

  • assetBundle = "..." - bundle name
  • prefabName = "..." - prefab name (not used if assetBundle is string)
  • pos = {x, y, z}
  • scale = {<Scale>} | 1.0
  • lookat = "..."
  • lookat = "camera" - look at camera
  • lookat = "start" - look at starting point
  • lookat = "..." - look at last ring
  • transform = {<Transform>}
  • layer = 0 ... 31
  • material = {<Material>}
  • materials = {<Material>...} - (not used if material is present)
  • prefabKeepExistingMaterial = true
  • shadowcaster = true|false
  • shadowreceiver = true|false

There are several more, but I don't terribly care much about this

Scale (Scale)

A table, with the following fields

  • min = 1.0 - min scale
  • max = 1.0 - max scale

Transform (Transform)

A table, with the following fields

  • position = {x, y, z}
  • rotation | rot = {rX, rY, rZ}
  • scale = {mX, mY, mZ}

Highway/track (Highway)

A table, with fields and member tables representing nodes

  • #n - Member tables, each represents a node
  • .maxair - Node max air
  • .minair - Node min air
  • .jumpairtime - Node jump air time
  • .pos - Node position (3 reals)
  • .seconds - Node length
  • .color - Node color
  • .r - Red
  • .g - Green
  • .b - Blue
  • .a - Alpha
  • .pan - Node rotation on the X axis
  • .tilt - Node rotation on the Y axis
  • .roll - Node rotation on the Z axis
  • .rot - Above rotation values as a vector (via LuaX.VectorToTable)
  • .intensity - Node intensity (normalized)
  • .funkyrot - ???
  • .antiairtime - Node anti-jump seconds
  • .trafficstrength - Node traffic strength
  • .antitrafficstrength - Node anti-traffic strength (???)
  • .slope - Node physical tilt (slope, "steep"-ness)
  • .intensityRaw - Raw intensity
  • minbounds - Min bounds (vector, via LuaX.VectorToTable)
  • maxbounds - Max bounds (vector, via LuaX.VectorToTable)
  • minslope - Min slope
  • maxslope - Max slope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment