Author Topic: Changing a function  (Read 3948 times)

Tenko Kuugen

  • Public Enemy
  • *
  • Posts: 1416
    • View Profile
    • Twitter
Changing a function
« on: 2011-02-14 17:45:43 »
I've planned to adjust all INNs in my mod to only restore HALF the HP / MP of everyone and don't touch status effects. Now, the game itself doesn't have such a function. ( oddly enough, there are 3 versions of "restore all HP / MP for every party member" and one that also removes status additionally )
Now, where would I find where that function is stored, and how would I go best about changing it?
( going in and removing the function and replacing it by 3x "increase hp" and 3x "increase mp" is not really an option because that screws with the script file too much )

Another thing: Tent's have a unknown function, but it's pretty clear they restore all HP / MP ( which is too powerful imo ) but I've no clue how to best change this. I thought about using the mega-lixir formula for this, but I found that to be working against me ( tents worked everywhere now ) I assume the tent function is stored in a script somewhere ( or it even accesses the same function as INNs which would help )

Then, is there a way to restore hp/mp by 50% with one item? recovery always restores you completely, regardless of what the item strength is. Using MHP * power and enabling "affect MP" results in a ether function.

On that note, is it possible to make status effects linger after the battle like anger / sadness? I guess the game lacks flags to set those statuses on a character but well, was worth asking.
« Last Edit: 2011-02-14 17:55:37 by KuugenTheFox »

Kudistos Megistos

  • Banned
  • *
  • Posts: 3929
    • View Profile
Re: Changing a function
« Reply #1 on: 2011-02-14 18:12:10 »
You might know as much about this as me, but just in case you don't:

This stuff is in the .exe file. If you want to change it you'll need a debugger a lot of luck; be aware that you might not be able to find out how to do this within a reasonable time frame. In fact, if you have to ask this question, you probably won't be able to do it.

Tenko Kuugen

  • Public Enemy
  • *
  • Posts: 1416
    • View Profile
    • Twitter
Re: Changing a function
« Reply #2 on: 2011-02-14 18:55:35 »
That's pretty much what I thought. So right now, I am making tents more expensive than scrooge mcduck's houses and increase the cost of Inns to compensate. You just will think twice about going to an Inn instead of using items if it costs you 40k gil.
Or tents simply are sold only in a few places.

Bosola

  • Fire hazard!
  • *
  • Posts: 1749
    • View Profile
    • My YouTube Channel
Re: Changing a function
« Reply #3 on: 2011-02-14 19:17:40 »
Well, you could use a debugger, and see what writes to party HP during an inn visit. Trace the logic, and you'll eventually find the algorithm. If you've never worked with assembler, though, it'll be a steep learning curve.

I've had enough trouble tracking down the poison function and getting it to deal a different fraction of damage.
« Last Edit: 2011-02-14 19:20:39 by Bosola »

nfitc1

  • *
  • Posts: 3013
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Changing a function
« Reply #4 on: 2011-02-14 19:27:08 »
If you're talking about the PC version I can probably help you.

...Tent's have a unknown function, but it's pretty clear they restore all HP / MP ( which is too powerful imo ) but I've have no clue how to best change this. I thought about using the mega-lixir formula for this, but I found that to be working against me ( tents worked everywhere now ) I assume the tent function is stored in a script somewhere ( or it even accesses the same function as INNs which would help )

Tents access the item function beginning at 0x717010 which will essentially mark which characters need to be healed. Then, it calls a function at 0x6CBA6A (Generic HP increase function) which will "heal" all characters by 10000HP/MP then cap it by their MHP/MMP. Now there's only five bytes to play with which is just one shy of being able to change this into anything dynamic. However, you can have tents only heal a static amount of HP/MP. You can change the value to cap them quite easily. Currently, the code to cap them is:

Code: [Select]
0x003164B5 : 68 10 27 00 00  --for HP
0x003164C6 : 68 10 27 00 00  --for MP

These translate into "PUSH 10000" which is in big-endian format. Changing it to, say:

Code: [Select]
0x003164B5 : 68 88 13 00 00  --for HP
0x003164C6 : 68 F4 01 00 00  --for MP

Would restrict tents to heal no more than 5000 HP and 500 MP. So the value you push will limit the healing it will do. I'm not going to go into how to do this. It requires a hex editor and an understanding of endianness.

That's the SIMPLE way to do it. If you wanted to get REALLY complicated you could re-write the whole tent function (or redirect it) to do something different. The function's range is between 0x717010 and 0x717123.

I've planned to adjust all INNs in my mod to only restore HALF the HP / MP of everyone and don't touch status effects. Now, the game itself doesn't have such a function. ( oddly enough, there are 3 versions of "restore all HP / MP for every party member" and one that also removes status additionally )
Now, where would I find where that function is stored, and how would I go best about changing it?
( going in and removing the function and replacing it by 3x "increase hp" and 3x "increase mp" is not really an option because that screws with the script file too much )

Inns won't touch status effects because they don't carry over as it is. I don't think that Inns use the standard heal function I was just talking about. Modifying it may be more difficult. I'm not sure where they are. I think making Inns more expensive would make more sense mechanically. The farther along in the game you are the more they should cost.

Then, is there a way to restore hp/mp by 50% with one item? recovery always restores you completely, regardless of what the item strength is. Using MHP * power and enabling "affect MP" results in a ether function.

You're looking at two separate actions if you want it to work the way you're thinking. First of all, make an item that restores 50% health:

Strength: 16
Damage: 24h (MHP * (strength / 32) )
Additional Effect 18h ( Perform action [index] upon completion )
Effect Modifier: 125 (any blank attack)

Then set up an attack that heals 50% MP at the index of the Effect Modifier.

Strength: 16
Damage: 24h (MHP * (strength / 32) )
Affect MP

I don't know if target data is reset between these actions so you may not get to choose the target of this second action (eg, if Cloud does gives the initial item to Barret, the second action might affect Barret OR Cloud). You can set the target data to only allow the person using it to use it on themselves and set the other action's target to the same thing.


On that note, is it possible to make status effects linger after the battle like anger / sadness? I guess the game lacks flags to set those statuses on a character but well, was worth asking.

Yes and no. There's no where in the characters' data to store those additional statuses. The Fury/Sadness is all part of one byte which is the first eight statuses (Death, Near-Death, Sleep, Poison, Sadness, Fury, Confuse, Silence). Those would be the only ones you could carry over, but as it is the game only allows Fury/Sadness to take effect at the start of a battle. Death is determined by HP (not the status) and even if you could have a character with those other statuses they wouldn't do anything outside of battle.

Tenko Kuugen

  • Public Enemy
  • *
  • Posts: 1416
    • View Profile
    • Twitter
Re: Changing a function
« Reply #5 on: 2011-02-14 19:38:29 »
Thanks, that was really helpful.
I adjusted the cost of Inns already, so I won't have to mess with that.
As for the item, it was mostly because I seperated Lixir and Mega-Lixir from Elixir and Mega-Elixir. I changed it now to that the lesser versions only affect HP so I won't have to deal with any messy attacks. Items should be constant, unlike spells.

The tents were my major issue, so i'll adjust them to 10,000 HP / 100 MP ( yes, that massive difference is intended )

The status stuff was just something I remembered from early FF games, where you stayed poisoned / petrified / etc after a battle. Would have put some importance on the single-cure allignment items

Bosola

  • Fire hazard!
  • *
  • Posts: 1749
    • View Profile
    • My YouTube Channel
Re: Changing a function
« Reply #6 on: 2011-02-14 19:53:43 »
Quote
I don't know if target data is reset between these actions so you may not get to choose the target of this second action (eg, if Cloud does gives the initial item to Barret, the second action might affect Barret OR Cloud). You can set the target data to only allow the person using it to use it on themselves and set the other action's target to the same thing.

I've done a lot of playing about with that function (Rebirth uses it for Darkside and Blood Price) so I might be able to help here.

A few relevant facts about this:

1. Target data is not reset, but it's trumped by the attack's targetting restrictions
2. The animation for the second attack is treated as existing in the same namespace as the first; eg. if you make a secondary attack with animation 0 follow a spell, the secondary attack will use spell animation zero (Cure)
3. If you plan on using this trick for enemy abilities, remember that Proud Clod / Wallmarket can't currently find secondary attacks that breach animation rules. FF7's exception handling can't diagnose them either - you'll get the bizarre message, "Data Error, Scene #$". If you see this, the animation you supplied for the secondary attack doesn't work, possibly because of point 2 above.

I should probably start a thread about the 'use attack X after completion' trick. It'll get ignored to death, just like my battle error thread, but hey, maybe it'll help someone someday.