Skip to content

Tools Lua

Neto Becker edited this page Jul 3, 2023 · 12 revisions

Shady Lua is a Module for SokuEngine. It allows to run Lua scripts to modify the game

C++ API

Include the script.hpp header to dynamically use the interface.

  // Creates a script (encapsulates a lua_State), using a path as root for the running scripts
  auto script = new ShadyLua::LuaScriptFS(rootFolderName);
  // Load a lua file from a path relative to the root
  if (script->load(filename) == LUA_OK) {
    // Execute the lua file
    script->run();
  }

Lua API

The lua code includes all default libraries.

Extra modules are described below:

Memory

memory -- namespace
  -- Read from memory into a string
  .readbytes(address, size) -- string(int, int)
  -- Read a double from memory
  .readdouble(address) -- number(int);
  -- Read a float from memory
  .readfloat(address) -- number(int)
  -- Read an integer from memory
  .readint(address) -- number(int);
  -- Writes a string into memory
  .writebytes(address, data) -- void(int, string)
  -- Writes a double into memory
  .writedouble(address, value) -- void(int, number)
  -- Writes a float into memory
  .writefloat(address, value) -- void(int, number)
  -- Writes an integer into memory
  .writeint(address, value) -- void(int, int)

Loader

loader -- namespace
  .basePath -- string
  .addData(name, data) -- bool(string, string)
  .addResource(name, resource) -- bool(string, resource.*)
  .addAlias(aliasName, targetName) -- bool(string, string)
  .addFile(name, path) -- bool(string, string)
  .addPackage(path) -- int(string)
  .removeFile(name) -- bool(string)
  .removePackage(id) -- bool(int)

Resource

Note: some resources can only be created after the Ready event

resource -- namespace
  .Type -- enum{Unknown, Text, Table, Label, Image, Palette, Sfx, Bgm, Schema, Texture}
  .createfromfile(path) -- resource.*(string)
  .export(resource, path) -- void(resource.*, string)
  .Text() -- class
    .data -- string
  .Label() -- class
    .begin -- number
    .end -- number
  .Palette() -- class (Note: channel range is 0-31)
    .data -- string
    .getColor(index) -- bool,int,int,int(int)
    .setColor(index, ?alpha, red=0, green=0, blue=0) -- void(int, ?bool, int, int, int)
  .Image() -- class
    .create(bpp, width, height) -- void(int, int, int)
    .width -- int
    .height -- int
    .paddedWidth -- int
    .bitsPerPixel -- int
    .size -- int
    .raw -- string
  .Sfx() -- class
    .channels -- int
    .sampleRate -- int
    .byteRate -- int
    .blockAlign -- int
    .bitsPerSample -- int
    .data -- string

Soku

soku -- namespace
  .BattleEvent -- enum{GameStart, RoundPreStart, RoundStart, RoundEnd, GameEnd, EndScreen, ResultScreen}
  .Character -- enum{Reimu, Marisa, Sakuya, Alice, Patchouli, Youmu,
      -- Remilia, Yuyuko, Yukari, Suika, Reisen, Aya, Komachi, Iku, Tenshi,
      -- Sanae, Cirno, Meiling, Utsuho, Suwako, Random, Namazu}
  .Scene -- enum{Logo, Opening, Title, Select, Battle, Loading, SelectSV, SelectCL,
      -- LoadingSV, LoadingCL, LoadingWatch, BattleSV, BattleCL, BattleWatch,
      -- SelectStage, Ending, Submenu}
  .Stage -- enum{HakureiShrine, ForestOfMagic, CreekOfGenbu,
      -- YoukaiMountain, MysteriousSeaOfClouds, BhavaAgra, Space, RepairedHakureiShrine,
      -- KirisameMagicShop, SDMClockTower, ForestOfDolls, SDMLibrary, Netherworld,
      -- SDMFoyer, HakugyokurouSnowyGarden, BambooForestOfTheLost, ShoreOfMistyLake,
      -- MoriyaShrine, MouthOfGeyser, CatwalkInGeyser, FusionReactorCore,
      -- SDMClockTowerBG, SDMClockTowerBlurry, SDMClockTowerSketch }
  .isReady -- bool
  .P1 -- battle.PlayerInfo
  .P2 -- battle.PlayerInfo
  .sceneId -- int
  .checkFKey(id) -- bool(int)
  .playSFX(id) -- void(int)
  .SubscribePlayerInfo(callback) -- int(function)
  .SubscribeSceneChange(callback) -- int(function)
  .SubscribeReady(callback) -- int(function)
  .SubscribeBattle(callback) -- int (function)
  .UnsubscribeEvent(int) -- void(int)

Battle

battle
  .Manager -- class
    .player1 -- Player
    .player2 -- Player
    .frameCount -- int
    .matchState -- int
  .PlayerInfo -- class
    .character -- soku.Character
    .teamId -- int
    .paletteId -- int
    .deckId -- int
    .inputType -- int
  .GameParams -- class
    .stageId -- int
    .musicId -- int
    .player1 -- battle.PlayerInfo
    .player2 -- battle.PlayerInfo
  .ObjectBase -- class
    .ptr -- int
    .position -- Point
    .speed -- Point
    .gravity -- Point
    .direction -- int
    .actionId -- int
    .sequenceId -- int
    .poseId -- int
    .poseFrame -- int
    .currentFrame -- int
    .opponent -- battle.Player
    .hp -- int
    .maxHp -- int
    .groundHeight -- int

    .createEffect(id, x, y, direction, layer) -- gui.Effect(int, number, number, int = 1, int = 1)
    .setActionSequence(actionId, sequenceId) -- void(int, int)
    .setAction(actionId) -- void(int)
    .setSequence(sequenceId) -- void(int)
    .setPose(id) -- void(int)
    .advanceFrame() -- bool()
    .resetForces() -- void()
    .isOnGround() -- bool()
  .Object -- class:ObjectBase
    .lifetime -- int
    .setTail(id, a, b, c, d) -- void(int, number, number, number, number)
    .getCustomData() -- string()
  .Player -- class:ObjectBase
    .character -- int
    .collisionType -- int
    .collisionLimit -- int
    .unknown4A6 -- int
    .groundDashCount -- int
    .airDashCount -- int

    .createObject(id, x, y, direction, layer, customData) -- battle.Object(int, number, number, int = 1, int = 1, string = "")
    .updateGroundMovement(x) -- bool(number)
    .updateAirMovement(x, y) -- bool(number, number)
    .addCardMeter(value) -- void(int)
    .applyGroundMechanics() -- bool()
    .applyAirMechanics() -- bool()
    .playSFX(id) -- void(int)
    .playSpellBackground(id, timer) -- 
    .consumeSpirit(cost, delay) -- 
    .consumeCard(index, costOverride, cardNameTimer) -- void(int, int = 0, int = 60)
    .eventSkillUse() -- void()
    .eventSpellUse() -- void()
    .eventWeatherCycle() -- void()

  .manager -- battle.Manager
  .gameParams -- battle.GameParams
  .activeWeather -- int
  .displayedWeather -- int
  .replaceCharacter(charId, update, initAction, initialize) -- void(int, callback, callback, callback)
  .replaceObjects(charId, update, initAction, initialize) -- void(int, callback, callback, callback)
  .random(maxPlusOne) -- int(int)

Gui

gui -- namespace
  .OpenMenu(onProcess) -- gui.Menu(function)
  .isOpenMenu() -- bool()
  .Menu -- class
    .renderer -- gui.Renderer
    .input -- gui.KeyInput
    .data -- {}
  .Scene -- class
    .renderer -- gui.Renderer
    .input -- gui.KeyInput
    .data -- {}
  .Renderer -- class
    .design -- gui.Design
    .effects -- gui.EffectManager
    .isActive -- bool
    .createSprite(name, x=0, y=0, w=-1, h=-1, ax=0, ay=0, layer=0) -- gui.Sprite(string, int, int, int, int, int, int, int)
    .createText(text, font, w, h, layer=0) -- gui.Sprite(string, gui.Font, int, int, int)
    .createEffect(id, x, y, dir=1, layer=0) -- gui.Effect(int, number, number, int, int)
    .createCursorH(width, max=1, pos=0) -- gui.Cursor(int, int, int)
    .createCursorV(width, max=1, pos=0) -- gui.Cursor(int, int, int)
    .destroy(object) -- gui.*
  .Design -- class
    .setColor(color) -- void(int)
    .loadResource(name) -- void(string)
    .clear() -- void()
    .getItemById(id) -- gui.DesignObject(int)
    .getItem(index) -- gui.DesignObject(int)
    .getItemCount() -- int()
  .DesignObject -- class
    .x -- int
    .y -- int
    .isActive -- bool
    .setColor(color) -- void(int)
    .getValueControl() -- {gauge, number}()
  .KeyInput -- class
    .axisH -- int
    .axisV -- int
    .a -- int
    .b -- int
    .c -- int
    .d -- int
    .change -- int
    .spell -- int
  .Sprite -- class
    .isEnabled -- bool
    .position -- Point
    .scale -- Point
    .rotation -- Point
    .setColor(color) -- void(int)
    .setTexture(name, x=0, y=0, w=-1, h=-1, ax=0, ay=0, layer=0) -- void(string, int, int, int, int, int, int, int)
    .setText(text, font, w, h, layer=0) -- void(string, gui.Font, int, int, int)
  .Cursor -- class
    .isActive -- bool
    .index -- int
    .setPosition(index, x, y) -- void(int, int, int)
    .setRange(x, y, dx, dy) -- void(int, int, int)
  .EffectManager -- class
    .loadResource(name, reserve) -- void(string, int)
    .clear() -- void()
    .clearEffects() -- void()
  .Effect -- class
    .isEnabled -- bool
    .isAlive -- bool
    .position -- Point
    .speed -- Point
    .gravity -- Point
    .center -- Point
  .Font() -- class
    .setFontName(fontname) -- void(string)
    .setColor(c1, c2) -- void(int, int)
    .height -- int
    .weight -- int
    .italic -- int
    .shadow -- int
    .wrap -- int
    .offsetX -- int
    .offsetY -- int
    .spacingX -- int
    .spacingY -- int

Clone this wiki locally