Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Neverwinter Nights: Enhanced Edition has been released! Visit nwn.beamdog.com to make an order. NWN:EE FAQ is available.
Soundtracks for BG:EE, SoD, BG2:EE, IWD:EE, PST:EE are now available in the Beamdog store.
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

[MOD] EEex (v0.6.0-alpha)

1356724

Comments

  • BubbBubb Member Posts: 641
    As kjeron has said, it is possible to do this with the normal UI modding capabilities. To be more specific, the function you would have to use to add unmemorized spells to contingencies / sequencers would be mageScreen:SequenceSpell().

  • subtledoctorsubtledoctor Member Posts: 11,136
    kjeron said:

    This is already doable with normal UI modding. You would still need a way to decrement the spells per day though.

    Huh. Maybe I was too discouraged by your comment in the other thread about sequencers and contingencies:
    kjeron said:

    Can I use this for a custom Contingency spell? And, how easily could it be Weiduized? Does it involve messing with finicky .lua files that cannot easily be patched by Weidu?

    This is pretty much why I never went any further with this idea. They have potential, but not accessibility to implement.
    As far as spells per day, well, I can probably figure that out. (I'm not actually using spells slots, but rather stat values in the upper bytes of Single-Weapon Style, so there's been a lot of figuring out with regard to that already. :wink: )
    Bubb said:

    As kjeron has said, it is possible to do this with the normal UI modding capabilities. To be more specific, the function you would have to use to add unmemorized spells to contingencies / sequencers would be mageScreen:SequenceSpell().

    That is utter gobbledegook to me. The rough idea is, make a variant version of Spell Sequencer for my kit, which would use known wizard spells (while the normal version of the spell remains the same for normal mages). In fact the normal Sequencer spell already seem do just that, for sorcerers.

    Is there somewhere around here where I can learn to do that? The couple of pinned threads in this subforum don't seem to speak to it. Would it be something like, creating an M_*.lua file? Which would contain something about "mageScreen:SequenceSpell()?" And then connect that to my custom Sequencer spell?

  • kjeronkjeron Member Posts: 1,965
    This probably isn't the best way, but it should work:
    COPY_EXISTING ~UI.MENU~ override
    	REPLACE_TEXTUALLY ~function[ %TAB%%WNL%]+filterContingencyMageSpells()~
    	~function	filterContingencyMageSpellsDisabled()~
    Create M_*.lua file, with contents:
    function	filterContingencyMageSpells()
    	local out = {}
    	if characters[id].mageSpells ~= nil and characters[id].mageSpells[currentSpellLevel] ~= nil then
    		for k,v in pairs(characters[id].mageSpells[currentSpellLevel]) do
    			if mageScreen:SpellAllowedForContingency(v.level, v.resref) then
    				if v.castableCount > 0 
    					tableInsert(out, v)
    				elseif contingencyResRef == "resource" then	-- custom sequencer/contingency spell resref, with quotes
    					tableInsert(out, v)
    				elseif contingencyResRef == "resource" then	-- custom sequencer/contingency spell resref, with quotes
    					tableInsert(out, v)
    				elseif contingencyResRef == "resource" then	-- custom sequencer/contingency spell resref, with quotes
    					tableInsert(out, v)
    				elseif contingencyResRef == "resource" then	-- custom sequencer/contingency spell resref, with quotes
    					tableInsert(out, v)
    				elseif contingencyResRef == "resource" then	-- custom sequencer/contingency spell resref, with quotes
    					tableInsert(out, v)
    				end
    			end
    		end
    	end
    	if characters[id].priestSpells ~= nil and characters[id].priestSpells[currentSpellLevel] ~= nil then
    		for k,v in pairs(characters[id].priestSpells[currentSpellLevel]) do
    			if v.castableCount > 0 and mageScreen:SpellAllowedForContingency(v.level, v.resref) then
    				tableInsert(out, v)
    			end
    		end
    	end
    	return out
    end
    
    --These add the correct labels/descriptions when setting the sequencer/contingency, the game crashes without them:
    mageBookStrings['resource'] = mageBookStrings['SPWI420'] -- Minor Sequencer clone, replace resource, keep quotes
    mageBookStrings['resource'] = mageBookStrings['SPWI710'] -- Spell Sequencer
    mageBookStrings['resource'] = mageBookStrings['SPWI809'] -- Spell Trigger
    mageBookStrings['resource'] = mageBookStrings['SPWI617'] -- Contingency
    mageBookStrings['resource'] = mageBookStrings['SPWI908'] -- Chain Contingency
    

  • BubbBubb Member Posts: 641
    As I'm sure everyone can tell from my relative absence, school started back up and I haven't had much time to play around with this project.

    Anyways - I had a thought while working on this today: why am I hard coding all of these functions? It's a literal hell to work with the assembly directly. I can easily externalize the ability to read arbitrary memory addresses to the LUA environment... so wouldn't it make more sense to deal with most everything there, where I don't cry out in agony every time I attempt to implement something?

    While I understand it can crash the game quite easily if the implementer is careless with the memory accesses, I think it is a much better system to allow anyone with some know-how to create new functions that tie into the engine.

    Here's an example of some LUA code I wrote that mimics an otherwise internal function that gets the currently selected creature's ID:
    function getSelectedCharacter()
    local eax = Infinity_ReadDWORD(0x93FDBC)
    local ecx = Infinity_ReadDWORD(eax + 0xD14)
    ecx = ecx + 0x3E48
    if Infinity_ReadDWORD(ecx + 0xD14) >= 0x0 then
    eax = Infinity_ReadDWORD(ecx + 0xC)
    eax = Infinity_ReadDWORD(eax + 0x8)
    else
    eax = bit.bor(eax, 0xFFFFFFFF)
    end
    return eax
    end


    Of course with enough research into where the engine stores various things in memory, any value can be accessed in this fashion.

    BrecherFaydark
  • GrammarsaladGrammarsalad Member Posts: 2,465
    I don't know enough about lua to comment. But, I think that you should do whatever works best for you.

  • GrammarsaladGrammarsalad Member Posts: 2,465
    edited November 2018
    Bubb said:

    Long time no see! I've been screwing around with this project for the last two days, and, well, I made a minimap? It's not very extravagant, but it works just the same.



    I've hardcoded 3 new LUA functions into the exe which allow me to read arbitrary memory addresses and call internal functions - leaving the actual implementation of exciting functions to UI.MENU. Here's the new functions I used to make the minimap, if anyone is curious:

    function getSelectedActorID()
    return rdword(rdword(rdword(rdword(0x93FDBC) + 0xD14) + 0x3E54) + 0x8)
    end

    function getActorDataAddress(actorID)
    local resultBlock = malloc(0x4)
    call(0x625C00, {resultBlock, actorID}, nil, 0x8)
    local result = rdword(resultBlock)
    free(resultBlock)
    return result
    end

    function getAllLoadedActorIDs()
    local ids = {}
    local eax = getActorDataAddress(0x0)
    local ecx = eax
    eax = rdword(eax)
    eax = call(rdword(eax + 0x1C), {}, ecx, 0x0)
    ebx = rdword(eax)
    repeat
    local actorID = rdword(ebx + 0x8)
    -- Check if it's actually an actor...
    -- apparently animations are also stored in this list.
    if rdword(getActorDataAddress(actorID)) == 0x8A86D0 then
    table.insert(ids, actorID)
    end
    ebx = rdword(ebx)
    until ebx == 0x0
    return ids
    end

    function getActorLocation(actorID)
    local dataAddress = getActorDataAddress(actorID)
    local x = rdword(dataAddress + 0x8)
    local y = rdword(dataAddress + 0xC)
    return x, y
    end

    function getActorsAreaSize(actorID)
    local address = rdword(getActorDataAddress(actorID) + 0x14)
    local width = rword(address + 0x4BC) * 64
    local height = rword(address + 0x4C0) * 64
    return width, height
    end

    -- Temporary soft-coded function to simulate
    -- reading a word...
    function rword(address)
    return bit32.extract(rdword(address), 0, 16)
    end

    function malloc(size)
    return call(0x886FD0, {size}, nil, 0x4)
    end

    function free(address)
    return call(0x7BF980, {address}, nil, 0x4)
    end
    Good to see you again. And you bring awesomeness!

    Is it possible to interact with the minimap, like say click on it to jump to that location, or maybe do that with the clairvoyance spell?
    Edit: Er, I mean the farsight spell

    Post edited by Grammarsalad on
  • BubbBubb Member Posts: 641

    *has chills*

    I must be doing the right things then! :)
    ------------------------------------------

    A quick question to all of you:

    While figuring out how to access the known spells table, I realized that the EE engine sorts the entries alphabetically whenever it accesses it. This completely destroys any persistent state of the order in which the player learned the spells to begin with.

    I figured out how to disable this sorting, (only a 14 byte change!). Would this be a desired? You could always sort the spells at run time instead of having the engine screw with the data structures themselves... though I'm not sure if there would be any use to changing the behavior.

    Here's an example of the change, spells learned in this order: Armor -> Blindness -> Chill Touch -> Chromatic Orb. (Most recently learned spells go on top... oldest on bottom)


    And here's what the Engine would normally do:

    Kilivitz
  • GrammarsaladGrammarsalad Member Posts: 2,465
    My guess is the reason they did that was so a player could more quickly find the spell they wanted (e.g. when looking for descriptions or for memorization). You might not remember the order that you learned your spells in, but its pretty easy to find your desired spell by alphabetical order.

  • GrammarsaladGrammarsalad Member Posts: 2,465
  • Permidion_StarkPermidion_Stark Member Posts: 4,082
    Bubb said:

    It's fully functional too, meaning that you can learn, unlearn, memorize, and unmemorize spells from the familar. I think persistent allies just got more interesting...

    Does this mean you can also teach your familiar new spells?

    GrammarsaladBubb
  • GrammarsaladGrammarsalad Member Posts: 2,465

    Bubb said:

    It's fully functional too, meaning that you can learn, unlearn, memorize, and unmemorize spells from the familar. I think persistent allies just got more interesting...

    Does this mean you can also teach your familiar new spells?

    I think that would be doable through dialog

    BubbPermidion_StarkCrevsDaak
  • FlashburnFlashburn Member Posts: 1,716
    That is incredible, @Bubb! Mage fencing will become so much easier!

    I have a suggestion, too, if I may:
    Could you make a countdown timer for when modal skills proc, like Bard Song/Detect Traps/Turn Undead?

    I find that when I'm trying to use Detect Illusions in combat once the skill is high enough, it's usually a gamble to see if my thief will dispel a mage's illusions in time before the mage casts another spell that my thief could get caught in. With the timer, I could see if it would be wiser to have my thief escape or stay a little longer so other party members can capitalize on the mage's illusions being shattered.

    Bubb
  • kjeronkjeron Member Posts: 1,965
    Flashburn said:

    I have a suggestion, too, if I may:
    Could you make a countdown timer for when modal skills proc, like Bard Song/Detect Traps/Turn Undead?

    You don't need any UI editing for this. Modal Abilties run on the same repeating interval as opcode 232 (cast spell on condition), so you can have the spell it casts display the countdown each second.

  • FlashburnFlashburn Member Posts: 1,716
    kjeron said:

    Flashburn said:

    I have a suggestion, too, if I may:
    Could you make a countdown timer for when modal skills proc, like Bard Song/Detect Traps/Turn Undead?

    You don't need any UI editing for this. Modal Abilties run on the same repeating interval as opcode 232 (cast spell on condition), so you can have the spell it casts display the countdown each second.
    I guess what I'm asking for is a little more ambitious than that. I don't want it clogging the combat log or displaying overhead text, and I don't think doing that will take into account if the mode is turned off before the ability actually activates.

    I want a small little countdown timer to the left of the quickloot diamond that is synced with the game's paused/unpaused state, starts and stops when the modal skill is turned on/off, and preferably with tenths of a second also displayed. Like this:

    Bubb
  • GreenerGreener Member Posts: 370
    @Bubb Incredible work! Out of curiosity, how would one incorporate these functions? For example Fatigue, luck, intoxication is this something that could be displayed on the character sheet as a value? Could it be updated in realtime? @lefreut

    Bubb
  • BubbBubb Member Posts: 641
    edited November 2018
    Greener said:

    @Bubb Incredible work! Out of curiosity, how would one incorporate these functions? For example Fatigue, luck, intoxication is this something that could be displayed on the character sheet as a value? Could it be updated in realtime? @lefreut

    @Greener: Sorry for the delayed response, school has kept me busy for the past few days. To answer your question, yes, these values can easily be added to the character sheet and be updated in real time using my functions :)
    kjeron said:

    Modal Abilties run on the same repeating interval as opcode 232 (cast spell on condition), so you can have the spell it casts display the countdown each second.

    @kjeron: After investigating the modal timer, I don't believe this is 100% true. While modal abilities and opcode 232 usually run very close together, they do actually use different internal timers.

    While opcode 232 uses a simple 100 tick countdown, modal abilities actually display some intentional randomness in their execution. Here's some pseudocode that controls the modal timer:
    idRemainder = actorID % 0x64 //Divide actorID by 100 and store the remainder
    modalRemainder = modalTimer % 0x64 //Divide modalTimer by 100 and store the remainder
    if idRemainder == modalRemainder then
    runModalAbility() //Actually execute the modal action
    end
    In normal people speak: the modal ability will randomly execute somewhere on the interval [0, 100] of the timer.

    Every actor in the game will evaluate a different number for the idRemainder, and thus the modal abilities of most creatures will be processed at different times. Perhaps the developers did this to spread out the operations to avoid lag, but it's an interesting finding regardless.

    @Flashburn: Would you also want the GUI to show the opcode 232 counter? This would allow the player to keep track of when any opcode 232 spells would execute, such as Globe of Blades.

    FlashburnGrammarsalad
  • kjeronkjeron Member Posts: 1,965
    Bubb said:

    @kjeron: After investigating the modal timer, I don't believe this is 100% true. While modal abilities and opcode 232 usually run very close together, they do actually use different internal timers.

    So it is, how odd. I know I've had the two run parallel before, must have been coincidence.

  • FlashburnFlashburn Member Posts: 1,716
    Bubb said:

    @Flashburn: Would you also want the GUI to show the opcode 232 counter? This would allow the player to keep track of when any opcode 232 spells would execute, such as Globe of Blades.

    Yes, as long as you can minimize its UI element. It will still be helpful to know when spells that use opcode 232 proc, but they're not quite as important as knowing when modal abilities will proc.

    Bubb
  • FlashburnFlashburn Member Posts: 1,716
    YESYESYESYESYES

    I just knew you could do it, I've been dying to have something like this for years!

    Bubb
  • BubbBubb Member Posts: 641
    So, I'm going to go crazy for a second and try to contemplate the impossible: would it be possible to unhardcode the 6 party-member cap?

    My findings suggest that while possible, it would be an extraordinary task even with the original source code. If my exe scrubber is correct, there are around ~250 hardcoded instances where the engine assumes that or checks against there being 6 party members. Every one of these cases would have to be looked at individually, and a unique fix applied. I am sorry, but I'm not going to go insane trying to do that...

    Here's what I am thinking: while a "correct" removal of the cap would be hell, would it be possible to fake it? Hear me out,

    I have already shown that the mage book can be completely detached from the engine's hardcoded implementation. I'm thinking it would be possible to do this with every GUI element that pertains to party members, such as the inventory and the character sheet.

    The ideal candidate for fake party members would be familiars, because the engine already treats them as fully-fledged characters, just with some artificial restrictions imposed.

    I've already removed the door-opening and area-transition restrictions from familiars. Interacting with containers crashes the game right now, but I'm pretty sure I can fix that.

    If you're still reading this, can you think of anything I've missed? Do familiars have any non-GUI restrictions beyond area transitions, door opening, and inventory management?

    Grammarsaladlolien
  • subtledoctorsubtledoctor Member Posts: 11,136

    Does this mean you can also teach your familiar new spells?

    I'm already working on this; though, as innate abilities rather than spells. TBH I'm not really convinced of the utility of using Vancian memorization instead of innate casting.

    (The best way, which I might implement, is to give them sorcerer-style spontaneous casting. So you could teach your familiar two spells of the same level (by sacrificing your own slots), and the familiar could cast both, or cast one of them twice, as the situation demands. A nice way to give mages a bit more flexibility in casting, and to mane familiars actually useful outside your backpack - and it's doable without this kind of UI/exe hack.)

  • GrammarsaladGrammarsalad Member Posts: 2,465
    edited November 2018
    Bubb said:



    ....

    I've already removed the door-opening and area-transition restrictions from familiars. Interacting with containers crashes the game right now, but I'm pretty sure I can fix that.

    If you're still reading this, can you think of anything I've missed? Do familiars have any non-GUI restrictions beyond area transitions, door opening, and inventory management?

    Removed restrictions: Wait, what!?! Awesome! What about restrictions to regular summons (e.g. area transitions?)

    Anything else: there actually may be a way around this that I don't know about but what about the limit of one familiar? And (in bg(2)ee at least) only allowing the protagonist to have a familiar

  • southfla79southfla79 Member Posts: 188
    Not sure if this is helpful but this mod has allowed NPC familiars for a while. Granted haven't used it much since I mainly play EET and the familiar stuff isn't compatible.

    https://forums.beamdog.com/discussion/18108/mod-more-style-for-mages-v1-55/p1#famnpc

  • GrammarsaladGrammarsalad Member Posts: 2,465

    Not sure if this is helpful but this mod has allowed NPC familiars for a while. Granted haven't used it much since I mainly play EET and the familiar stuff isn't compatible.

    https://forums.beamdog.com/discussion/18108/mod-more-style-for-mages-v1-55/p1#famnpc

    Oh that's right. I remember @swit saying that eet externalizes familiars

Sign In or Register to comment.