News:

The forum has been updated to SMF (2.1.3)!
Please be patient as we work to polish up the place and update features as we can.

Main Menu

GS2 Utility Script

Started by Plexa, 07, October, 2016, 08:50:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Daddy Poi's Oily Gorillas

#20
QuoteGood catch on the *5 error! Probably would have never found that myself since its so rare that you even get 5 enemies (to the point where I never bothered including them in the flee calculation).
If I'm not mistaking, the maximum number of enemies that can be in a battle should be six. But I'm not too worried about that since it's obvious your script is for speedrunning, and that you won't come across that.

QuoteI don't know enough LUA to be able to answer your question about calling thumb functions. I imagine there is since it is possible to write to RAM (we use that to suppress encounters when hunting for oob doors).
There is a pointer list that point to functions to be called every frame at 02003610... But actually inserting functions may be the harder part if you only want just a LUA script to be messed with. (You can probably still insert hex to WRAM/IRAM that represents code and point it there.) - In the case it is used, I would recommend a simple code that just calls functions with arguments and puts return values in a specific place in RAM for use. While also resetting back the RNGs as if they were never used by these specific calls. (Assuming that's all that would be necessary from a *simple* LUA script that doesn't want to duplicate potentially(?) unnecessary things... etc.)

QuoteInteresting that there's a random increased drop chance, keep me posted on what you find.

Looking at your script is what got me looking into that in the first place... The basic details is that it only works with using djinn that are of the same element as the weakest elemental resistance of the enemy, and from there, the chance to quadruple the item chance is (Attacker ePower - Defender eResist + 30) * 655 > BRN(,0xFFFF) ... So basically you only need like 71 difference to ensure 100% chance of quadrupling, it seems. I'll give a bit more info, though....

QuoteEDIT: Are you sure that you're not just talking about rainbow killing enemies xD
Pardon?


Anyway, there are two places in the code that are notable. (+ 1~2 other places that are not-so-important, that I may skip having a specific explanation on.)  I'll start with the Damage Formula.

---
08120454 = Damage Formula
[sp, 0x18] Initially set to 0.

081205E8 = Elemental check (I think.) and,  [sp,0x18] = -1 when the element of use is one which the enemy is strongest in.
08120620 = [sp,0x18] = 1 when the element of use is one which the enemy is weakest in.
08120646 = Basically an element check for Neutral(4+), and a check for if using item - Both do [sp,0x10]=0x64 , which represents ePower. (Not really that useful though, since we branch out anyway? Except in the case where these variables could be used for other things?)
08120668 = Check for if it is djinn being used.
08120672 = Element check... 4 is neutral so it doesn't have a chance to quadruple rate, anything above 4 should be never used.
08120676 = Checks [sp,0x18] , if it is <= 0 ,  branches out... So anything other than the weakest enemy elemental resistance of the enemy doesn't have a chance to quadruple the item chance.
0812067C = The (Attacker ePower - Defender eResist + 30) * 655 > BRN(,0xFFFF) calculation.
081206A4 = Function call that puts in vars 0xD, 0x5... (0x5 is probably unused..?) ... when those (at least the 0xD) are evaluated later, it sets 0203089C to 1, which is responsible for the quadrupled chance.

---
0812824C = What happens when an enemy dies... (Coin/Exp/Item reward.... etc.) Not the same as the next function (End-of-battle), but sets up data that that function uses....

r8 = Enemy data (ROM) address.
r11 = The argument of the function is pute here, but that number should be the number at 0203089C. (Representing the quadrupler.)
r12 = address of the chance value.

0812844C = Get item chance.  If the quadrupler is not 0, then subtract 2 from it. Minimum cap is 0.  (That is the quadruple effect.)
0812845A = (0x20000 >> chance value) > BRN(0,0xFFFF)

---

Small Work-In-Progress C++ script that I made for future use... (I think it is more of an alternative version meant to be compiled/inserted into ROM rather than a replacement, though? Unless you don't mind switching your method. :P)
I know for sure that I prefer C++ more than LUA, so it shouldn't be too much of a bother for people who think the same. XD

Trivial notes about GBA/C++ code:
#defines = Basically code substitution... in my opinion. You can still use local variables from functions into them as well... (Can make it easier to read. And doesn't really change how something is compiled. (Unless the optimizer makes note of it, dunno.))
32-bit number = (int)Number
Pointer to 32-bit data = (int*)Pointer
32-bit value at pointer = *(int*)Pointer
^ Here, "Pointer" (for the GBA) should be 32-bit regardless of data-type?

For the GBA, anytime a local variable is used, it should always be 32-bit (esp. iterators/loop index variables.), or else you may get extra shifts. (May not matter if your optimizer can detect/remove them, though... but we can do it just to be safe.) - Global/RAM variables, you can do whatever you want. :)
[spoiler]//GS2 Utility Script
//Original version was by Plexa, this version is by Teawater.
//Direct function calls to: reduce bugs, cleanliness, and increased compatibility for anyone interested in ASM hacks.
register int *r4 asm ("r4"); //Allows variable "r4" to use register "r4"...

int getItemSlot(pc, item) {
r4 = (int*)0x080AEE98; goto *r4;
}
int psyCheck(pc, ability) {
   r4=(int*)0x080AF4B9; goto *r4;
}
int unleashCheck(int pc) { //Returns ability used.
   r4=(int*)0x080B04BD; goto *r4;
}
int effectSuccess(int attacker, int defender, int element, int effect, int percentMod) {
   r4=(int*)0x080B075D; goto *r4;
}
int fleeSuccess() {
   r4=(int*)0x0811CE95; goto *r4;
}

#define AD3 *(int*)0x0200049A
#define BRN *(int*)0x020054C8
#define GRN *(int*)0x030011BC
int main() {
int brn = BRN, grn = GRN;
//gui.text(160,00,"BRN: ".. (memory.readdword(AD4)))
//gui.text(160,10,"GRN: ".. (memory.readdword(AD5)))
//In battle:
//gui.text(0,20,"Encounter: ".. (memory.readword(AD3)))
//Missing Agility Stats...
//GRN/BRN counts.
int count = 0;
while ((fleeSuccess() == 0) && (++count <= 100)) { }
BRN = brn; GRN = grn; count = 0;
int pc = 0;
while (pc < 8) {
if (getItemSlot(pc, 0xE3) != -1) { //Sleep bomb - Sleep effect
while ((effectSuccess(pc, 0x80, 3, 24, 64) == 0) && (++count <= 100)) { };
BRN = brn; GRN = grn; count = 0;
}
if ((psyCheck(pc, 0x112) == 0)) { //Weaken - Resistance effect
while ((effectSuccess(pc, 0x80, 3, 16, 64) == 0) && (++count <= 100)) { };
BRN = brn; GRN = grn; count = 0;
}
pc++;
}
//Drop Stuff to come.

return 0;
}
[/spoiler]
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

"Rainbow Kills" are when you kill an enemy with a djinn of an element that the enemy is weak to, this gives bonus exp and item drop chance (tons of stuff on gamefaqs about this). Sounds like that is what this code is referring to.

leaf

Yeah, it's definitely referring to rainbow kills. I already knew that rainbow kills could fail as a result of insufficient epow, but didn't know the exact threshold.
[spoiler=quotes]
[9:00:50 PM] Randel Peltier: Ok...what did I do last night?
[9:01:19 PM] Kain: Something boring, repetitive, and lasted for about sixty seconds.
---
[10:45:08 AM] Salanewt: But yeah, the elemental phalluses are being... Stroked up by Saturos and co., and the energy will go towards... Mt. Muffin, where the Golden Climax will arise.
[7:28:42 PM] Salanewt: An added bonus is that Isaac and co. were trying to stop Saturos and co. because their beliefs state that Mt. Muffin should remain a virgin.
---
[9:54:21 PM] Randel Peltier: Guess the number in my head an you get to pick what I say. Number between 1-10
[9:54:28 PM] leaf: 11
[9:54:36 PM] Randel Peltier: @#$%!
---
[8:38:13 PM] Randel Peltier: Shes like this queen up on a pedastal that I have yet to court.
[8:38:29 PM] Kain: You've tried courting her.
[8:38:43 PM] leaf: and failed spectacularly
[8:38:44 PM] Randel Peltier: Ive tried...shes the best dating game ever.
---
[12:24:35 AM] Salanewt: I need to find a picture of a naked person to put on the Christmas tree next year.
---
[2:19:06 PM] Zeadra: wait... Rief's a guy???
---
[1:09:57 PM] Zeadra: well if you want to know if its a new effect or something weird, just check GS1, if side step is there maby it is the nimble dodge thing
[1:10:35 PM] Kioll: For once, you've contributed something useful.  o.O[/spoiler]

Daddy Poi's Oily Gorillas

#23
@Rainbow kills: Oh... You have a point, hahah... Well, at least we know where the code for it is now, right? :)
One guide seems to think Luck is a factor? (Not directly stated.) I didn't see anything on that, but can we say whether it is or isn't?
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

leaf

Does that function reference luck? I think you have your answer.
[spoiler=quotes]
[9:00:50 PM] Randel Peltier: Ok...what did I do last night?
[9:01:19 PM] Kain: Something boring, repetitive, and lasted for about sixty seconds.
---
[10:45:08 AM] Salanewt: But yeah, the elemental phalluses are being... Stroked up by Saturos and co., and the energy will go towards... Mt. Muffin, where the Golden Climax will arise.
[7:28:42 PM] Salanewt: An added bonus is that Isaac and co. were trying to stop Saturos and co. because their beliefs state that Mt. Muffin should remain a virgin.
---
[9:54:21 PM] Randel Peltier: Guess the number in my head an you get to pick what I say. Number between 1-10
[9:54:28 PM] leaf: 11
[9:54:36 PM] Randel Peltier: @#$%!
---
[8:38:13 PM] Randel Peltier: Shes like this queen up on a pedastal that I have yet to court.
[8:38:29 PM] Kain: You've tried courting her.
[8:38:43 PM] leaf: and failed spectacularly
[8:38:44 PM] Randel Peltier: Ive tried...shes the best dating game ever.
---
[12:24:35 AM] Salanewt: I need to find a picture of a naked person to put on the Christmas tree next year.
---
[2:19:06 PM] Zeadra: wait... Rief's a guy???
---
[1:09:57 PM] Zeadra: well if you want to know if its a new effect or something weird, just check GS1, if side step is there maby it is the nimble dodge thing
[1:10:35 PM] Kioll: For once, you've contributed something useful.  o.O[/spoiler]

Daddy Poi's Oily Gorillas

#25
Well, I did say I didn't see it in this area? So I guess not...

@Article: It did seem mostly implied, however, don't really know what else they'd refer to.
Was just asking in case I missed something somewhere else...
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

Quote from: leaf on 11, October, 2016, 09:47:04 PM
Yeah, it's definitely referring to rainbow kills. I already knew that rainbow kills could fail as a result of insufficient epow, but didn't know the exact threshold.
Thats interesting, I thought it was something that just depended on BRN I had no idea that it was a check against elemental power !

Rolina

Nope!  That's why RNG exploits for item drops recommend base classes.

Daddy Poi's Oily Gorillas

#28
In your Speed Run, do you get any Sleep Bombs via using Scoop on the ground? (It's a random reward.)
Would it be worth considering adding a display for that to your script? (Or is Scoop retrieved a little too late (Yampi Desert) for it to be useful? - Although, I should probably check the first enemies with that reward and maybe I'll have my answer.)

@Scoop: Should be a random number for if something is rewarded? (Probably 1/16?) There are a few GRNS, so....

Hmm... (GRN < 0xC000  = Item rewarded))
Coins (1/4?) - Amount to reward would be ((2nd GRN * level) << 1 >> 0x10) + 1.
Item Rewarded (3/4) ==>
080F0FC0 = Item list (Chosen by random number from 0x0-0xF.) ((2nd GRN << 4) >> 0x10)
Herb (1/4)
Antidote (3/16)
Smoke Bomb (1/8)
Sleep Bomb (1/8)
Game Ticket (3/16)
Nut (1/8)

Sleep Bomb dropping enemies:
Enemy - Weakest Resistance (Initial chance of item reward.)

Death Cap - 7 Mars (1/32)
Aqua Jelly - 7 Mars (1/32)
Mini-Goblin - 48 Jupiter (1/16)
Bone Fighters - 25 Venus (1/32)
Kobolds - 48 Jupiter (1/16)
Slayers - 72 Jupiter (1/32)

Obviously, Slayers are worst choice... but the others could be reasonable.


@Staff of Anubis: Should be 0x144, and not 0x44.
Red Demon - 72 Jupiter (1/64)
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

We use exactly two sleep bombs; one on King Scorpion and the other on Avimander. Both are easily obtainable from Inns. But I'll keep this in mind and pass it on to Zetonegi who might have a use for it (he does japanese which has precise RNG control).

Speaking of Japanese... looks like the ROM is very different from the English one. First, the items are out of order compared to english (0x44 is supposed to be the Staff of Anubis but in Jap it is 0x144). Second, enemy data in the ROM (looked up via enemy index) is all over the place and the old calculations don't work. By chance do you have any insights there?

Daddy Poi's Oily Gorillas

#30
QuoteFirst, the items are out of order compared to english (0x44 is supposed to be the Staff of Anubis but in Jap it is 0x144).
Nah. It's 0x144 on both (U) and (J)... Unless I'm missing something. (I checked just now by giving the item to a PC.... from the PC RAM data.)

So yeah... that post still goes:
Quote@Staff of Anubis: Should be 0x144, and not 0x44.
Red Demon - 72 Jupiter (1/64)

@Enemy data: Probably just a simple base address change for each ROM table. You probably should be doing this anyway, but create a variable for each base address of a table... And the Localization will determine what the address is for each.

080B9E7C = (U) version Enemy data

080B4E4C = (J) version Enemy data


So yeah... Everything is basically there, but  the (J) version is of a slightly earlier address... (You can find it by searching for matching data between (U) and (J) versions if you want.)
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

Thanks for that! I never anticipated doing any work with JP but making it a variable sounds like a good idea.

Plexa

Hey just checking.... but when fleeing after the reunion does it consider the party level to be the average of all 8 members (assuming they're alive) or just the front four?

Daddy Poi's Oily Gorillas

#33
Should be just the living PCs in front.
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

My script is returning a lower rate of flee success than what the game is - afaik it's only happening after the reunion. Any idea what is wrong?

if memory.readword(0x02000420) == 0x1FE then                 -- if in battle then do the following

if el4 ~= 0 then                                 --Hacky way of getting the enemy level; doesn't work for 5+
ela = (el1+el2+el3+el4)/4
elseif el3 ~=0 then
ela = (el1+el2+el3)/3
elseif el2 ~=0 then
ela = (el1+el2)/2
else
ela = el1
end

pc1 = memory.readbyte(0x02000458)
pc2 = memory.readbyte(0x02000459)
pc3 = memory.readbyte(0x0200045A)
pc4 = memory.readbyte(0x0200045B)
if party == 0x70 then
ml = (memory.readbyte(0x02000520+0x14C*pc1+0xF)+memory.readbyte(0x02000520+0x14C*pc2+0xF)+memory.readbyte(0x02000520+0x14C*pc3+0xF))/3
else
ml = (memory.readbyte(0x02000520+0x14C*pc1+0xF)+memory.readbyte(0x02000520+0x14C*pc2+0xF)+memory.readbyte(0x02000520+0x14C*pc3+0xF)+memory.readbyte(0x02000520+0x14C*pc4+0xF))/4
end

LevelAve = ml-ela

fleeFail = memory.readbyte(0x02030092)

function flee(S) -- Flee Success Calculation
g = S
g = RNB(g)*10000
fl = 5000 + (2000*fleeFail) + (LevelAve * 500)
g = bit.rshift(g, 16)
if fl >= g then
return true
else
return false
end
end

Daddy Poi's Oily Gorillas

#35
Huh... That's strange.
Is it corrected when you remove the last four PCs (after reunion and before entering battle)?
(I assume you're only Fleeing at the beginning of a battle - so we skipped checking for whether they were living or not.)

I might have to run your script in a bit... and maybe compare with SDL-H.... so not sure what's going on yet.

Quoteif fl >= g then
      return true
   else
      return false
   end
This can be reduced to "return fl >= g" ...


Or rather, since I like short code, more like:

function flee(S) -- Flee Success Calculation
   return ((5000 + (2000*fleeFail) + (LevelAve * 500)) >= (bit.rshift(RNB(S)*10000, 16)))
end

But if you like things split up... this works too: (Probably the easiest to read of all of these?)

function flee(S) -- Flee Success Calculation
   fl = 5000 + (2000*fleeFail) + (LevelAve * 500)
   g = bit.rshift(RNB(S)*10000, 16)
   return fl >= g
end



[spoiler=------- Fun thought -------]If LUA has any dictionary types... I bet this could be shortened way down: (Best case scenario is... possibly a one liner inside the function...?)
Quotefunction bchance (E) -- base chance for status
    if E == 16 or E == 17 then
        c = 75
    elseif E == 23 then
    c = 40
    elseif E == 24 then
    c = 45
    elseif E == 27 then
    c = 20
    end
    return c
end
I'm thinking something like: (Not tested of course.... But you can do this type of thing in Python... however, here... I try to write in LUA..., so I should look into it.)
return {[16]=75, [17]=75, [23]=40, [24]=45, [27]=20}[E]

After testing, LUA seems to not allow for the [E] part... unless I missed something. (There might be a way, but??) ...so you may have to assign the dictionary to a variable first...

c = {[16]=75, [17]=75, [23]=40, [24]=45, [27]=20}
return c[E]

Should do it.

I wouldn't recommend a one liner unless it is a small dictionary, though... and I think this is small enough. (If it was long, you could put each element on a separate line - simple, I think.)[/spoiler]

So are you planning to make a big edit to your GS2 Script? Or is it just bug fixes?
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

I just went through and checked everything by having my script print intermediate variables and whatnot; I can't see any issue with what's going on. Maybe I just misread errors earlier on... can't seem to replicate the behavior anymore =/

Daddy Poi's Oily Gorillas

#37
Interesting... So there are no errors?

Only possibilities I can think of at the moment are these:
-You misread something.
-Killed off an enemy ... maybe/maybe not used a savestate/forgot it won't the start of the battle.
-Started a battle with 5+ enemies/forgot that there wasn't support for that.

Etc.


---
So I googled golden sun hacking in my emails.... Found out you mailed me on youtube in 2013, but I can't access the whole message... I think b/c youtube doesn't do Inbox anymore?.... Do you remember what it was about?
It linked to this topic (http://forum.goldensunhacking.net/index.php?topic=1632.0 ) ... but the message cuts off (with "more" as a link to a Not Found page.)

Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Plexa

Would have been about RNG stuff, we knew nothing back then! xD