Jump to content
Sign in to follow this  
Taimon

Lua console

Recommended Posts

I've a played a bit with the Lua console in BG2.

 

Firstly, BG2 uses Lua version 3.0, which of course is outdated right now, but the docs are still online.

(You can check this by typing "CLUAConsole:DisplayText(_VERSION)" in the console.)

 

The game automatically sources "luaAuto.cfg", so if you have any startup code for the console, you might want to put it in this file. (in the game directory)

 

If you are not familiar with Lua, let me note this: you can source any file you want by doing 'dofile("filename")', so if you modified your code and don't want to reload, just dofile it in again.

 

This is my current luaAuto.cfg:

(I'll explain parts of it later.)

chitin = GetBaldurChitin()	  -- CBaldurChitin
game = chitin:GetObjectGame()   -- CInfGame
timer = game:GetWorldTimer()	-- CTimerWorld
options = game:GetOptions()	 -- CGameOptions
-- static: CLUAConsole / CLUACheats

-- interesting options:
--  options.m_bDisplayExtraCombatInfo (0) [does nothing?]
--  options.m_bStupidQuickItemStuff   (1) [disables magic ability icon for Boo]
--  options.m_nDifficultyMultiplier   (0)
--  options.m_bAutoPauseCenter		(1)
--  options.m_bForceDialogPause	   (0)
--  options.m_nAreaEffectsRefreshProb (100)

-- AdvanceCurrentTime
-- sets the time of day to the ticks value
-- works like the DayNight action (if current_time > ticks -> next day)
-- ticks refers to ingame clock ticks:
--   one second ->	 15
--   one hour   ->   4500
--   one day	-> 108000
-- constants:
--   timer.TIME_DAWN  -> 27000
--   timer.TIME_DAY   -> 31500
--   timer.TIME_DUSK  -> 94500
--   timer.TIME_NIGHT -> 99000
function advanceTime(ticks)
timer:AdvanceCurrentTime(ticks)
end


-- aliases

function print(msg)
CLUAConsole:DisplayText(msg)
end
p = print

function setGlobal(str,value,area)
value = value or 1
area = area or "GLOBAL"
CLUAConsole:SetGlobal(str, area, value)
end
sg = setGlobal

function getGlobal(str, area)
area = area or "GLOBAL"
CLUAConsole:GetGlobal(str, area)
end
gg = getGlobal

 

Well, the first few lines initialize some data structures you don't really need, but I was curious about them.

By the way, comments in Lua start with a '--'. :D

 

I've note some of my findings below: Some game options that weren't documented anywhere (default value in parentheses) and a function to advance the ingame time.

 

In the last part, I've defined some aliases to save time while interacting with the console.

So I just had to type "p(options.m_gore)" to get the value of the gore option or 'sg("var")' to set the global "var" to 1.

Feel free to add some of your own. :D

 

When you are testing a mod, it could also be handy to define a function that does the basic setup for your test case, e.g.:

function setupTest()
CLUAConsole:CreateItem(...)
CLUAConsole:CreateCreature(...)
...
end

Share this post


Link to post

Wow. Almost as good as the guiscript in gemrb :D

A pity you found this only after 8 years :D

 

At least, the autostart file could be used to set up the cheats everytime.

Share this post


Link to post

IIRC, BG shipped with the startup conf (although I don't remember anybody doing very much with it).

 

I'm not sure how much is exposed to lua outside the options and debug cheats, though? It mostly looks like just everything you've used and some graphics junk are the only new bits.

Share this post


Link to post

Yep, there isn't much more in the Lua interface, but it could provide pointers to the main data structures of the game. (CInfGame)

Share this post


Link to post

It's actually easy to find pointers to all the main structures of the game by looking at the assert()s that the code makes. It's helpful that you have names of the structs and some of the constants as well; for my purposes, that is. How many members can you decode from the 4DC8h size CInfGame and 720Ch size CBaldurChitin?

Edited by Ascension64

Share this post


Link to post
-- options.m_bDisplayExtraCombatInfo (0) [does nothing?]

-- options.m_bForceDialogPause (0)

 

These two are actually implemented and work correctly. You can also set them baldur.ini by adding the corresponding lines. Here's a quote from Power Users.txt:

 

Extra Combat info:

Found in [Game Options]:

 

Extra Combat Info=1

 

When activated, displays all hit roll and damage roll

calculations in detail.

 

Dialogue Pausing:

Found in [Game Options]:

 

Force Dialog Pause=0

 

When activated, causes non-pausing dialog to be deactivated.

Share this post


Link to post

I thought most of this was already known. I have a file dated 2005 (from the timestamp on my disk - I'm sure the original is older) describing a chunk of this. I could never actually do anything useful with any of it though (perhaps because the file seems to be in Polish...).

Share this post


Link to post
These two are actually implemented and work correctly. You can also set them baldur.ini by adding the corresponding lines. Here's a quote from Power Users.txt:
Yeah. The auto-center is actually a GUI option. AoE refresh can also be set in .ini, but I don't remember if it did anything (I seriously doubt; the corresponding density setting is used by default, but I don't remember it doing anything noticeable either).

 

The dumb QI and the SP and MP difficulty *s are unknown (to me at least).

Share this post


Link to post
The dumb QI and the SP and MP difficulty *s are unknown (to me at least).

 

I think "StupidQuickItemStuff" might be this:

 

Quick Item Mapping:

Found in [Game Options]:

 

Quick Item Mapping=1

 

When activated, only the abilities from items in the quick

item slot can be mapped. When deactivated, any ability

from any item can be mapped into the quick item slot.

 

The difficulty multipliers might refer to the damage increase/decrease caused by game difficulty settings other than Core Rules.

Share this post


Link to post

That's what I originally thought (there is no lua binding for "QuickItemMapping"), but I don't really know what Quick Item Mapping does either (I remember turning it off once and not being able to find any difference in behavior). Maybe Power Users don't need to be told what the hell abilities from items are being mapped to for that desc to make any sense?

Share this post


Link to post
That's what I originally thought (there is no lua binding for "QuickItemMapping"), but I don't really know what Quick Item Mapping does either (I remember turning it off once and not being able to find any difference in behavior). Maybe Power Users don't need to be told what the hell abilities from items are being mapped to for that desc to make any sense?

 

When turned on, it allows you to use any quick item ability (wand, potion... etc.) through the "Use Item" GUI button.

 

Kinda pointless IMO, but it does function as advertised, and it's easy to test in practice.

Share this post


Link to post

So... if it's on, then quick items with abilities show up in the "Use Item" submenu, and if it's off, only non-quick item abilities show up? Or is it the other way around? Or what?

 

I'm totally clueless here because I don't remember ever seeing quick items show up in the Use Item submenu... assuming that 1 is "on" and 0 is "off," it's always been on here.

 

If this isn't the StupidStuff they're referring to, it certainly qualifies... ;-)

Share this post


Link to post
So... if it's on, then quick items with abilities show up in the "Use Item" submenu, and if it's off, only non-quick item abilities show up? Or is it the other way around? Or what?

 

In the unmmodded game, this is the default setting:

 

Quick Item Mapping=1

 

Now, if you change that to:

 

Quick Item Mapping=0

 

then you can use potions, wands and other quickslot items through the "Use Item" GUI button.

 

I'm totally clueless here because I don't remember ever seeing quick items show up in the Use Item submenu... assuming that 1 is "on" and 0 is "off," it's always been on here.

 

You probably added a new line containing this setting instead of changing the existing one (there's one by default in the unmodded baldur.ini).

Share this post


Link to post
You probably added a new line containing this setting instead of changing the existing one (there's one by default in the unmodded baldur.ini).
Ah, like I said, it's always been 1 (I know it's a default setting, but I didn't recall if it defaulted to 0 or 1 or whatever), so I guess they chose the sensible default of not cluttering the Use submenu. Good to know, thanks.

Share this post


Link to post
I thought most of this was already known.

This doesn't claim to be any kind of discovery or something, I just couldn't decide where to put it (tutorials?) and thought this forum fits best. (On a side note: I only started digging into the IE very recently, so I actually might come up with a lot of things you guys already know about. Will check more thoroughly in the future, though.)

 

How many members can you decode from the 4DC8h size CInfGame and 720Ch size CBaldurChitin?

Haven't looked into any of them, yet.

Instead of doing some structured reversing, I'm more of an amateur and simply try to take a peek at things when something sounds interesting.

 

Extra Combat info:

Found in [Game Options]:

 

Extra Combat Info=1

 

When activated, displays all hit roll and damage roll

calculations in detail.

This doesn't work for me (that's why I posted it).

m_nEffectTextLevel controls what is shown in the text window. (The first bit toggles the hit rolls. See the feedback options in the preferences.)

 

By the way, is the research topic still up-to-date? :D

Share this post


Link to post
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...