Difference between revisions of "Save Unit to Party"
Jump to navigation
Jump to search
(Created page with " # ROUTINE: SAVE UNIT TO PARTY # Parameters: # r4 = (unit) Unit in-battle data pointer # r5 = (isGuest) Whether to save as guest # Return...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 19: | Line 19: | ||
80059bd8: 10400003 beq r2,r0,0x80059be8 | 80059bd8: 10400003 beq r2,r0,0x80059be8 | ||
80059bdc: 30630001 andi r3,r3,0x0001 # isSavingAsGuest = unit.Flags & ENTD_FLAG_JOIN_AS_GUEST | 80059bdc: 30630001 andi r3,r3,0x0001 # isSavingAsGuest = unit.Flags & ENTD_FLAG_JOIN_AS_GUEST | ||
− | # if ((unit.BaseClass | + | # if ((unit.BaseClass >= 0x80) // Unit is generic |
80059be0: 14a00002 bne r5,r0,0x80059bec # or (isGuest == 0)) | 80059be0: 14a00002 bne r5,r0,0x80059bec # or (isGuest == 0)) | ||
80059be4: 00000000 nop # { | 80059be4: 00000000 nop # { | ||
Line 34: | Line 34: | ||
80059c08: 2e020015 sltiu r2,r16,0x0015 | 80059c08: 2e020015 sltiu r2,r16,0x0015 | ||
# if ((unit.PartyIndex >= 16) and (unit.PartyIndex <= 19)) { // If already a guest | # if ((unit.PartyIndex >= 16) and (unit.PartyIndex <= 19)) { // If already a guest | ||
− | 80059c0c: 0c0167f8 jal 0x80059fe0 # [[Remove Unit | + | 80059c0c: 0c0167f8 jal 0x80059fe0 # [[Remove Unit from Party]] (unit.PartyIndex); |
80059c10: 00000000 nop | 80059c10: 00000000 nop | ||
80059c14: 00002021 addu r4,r0,r0 | 80059c14: 00002021 addu r4,r0,r0 |
Latest revision as of 23:12, 1 May 2020
# ROUTINE: SAVE UNIT TO PARTY # Parameters: # r4 = (unit) Unit in-battle data pointer # r5 = (isGuest) Whether to save as guest # Returns: # r2 = 0, if unit saved successfully # = -1, if unit didn't save because there was no slot to save into 80059bb0: 27bdffd8 addiu r29,r29,-0x0028 80059bb4: afb20020 sw r18,0x0020(r29) 80059bb8: 00809021 addu r18,r4,r0 # unit 80059bbc: afbf0024 sw r31,0x0024(r29) 80059bc0: afb1001c sw r17,0x001c(r29) 80059bc4: afb00018 sw r16,0x0018(r29) 80059bc8: 92430006 lbu r3,0x0006(r18) # unit.Flags // "Gender" byte 80059bcc: 92420000 lbu r2,0x0000(r18) # unit.BaseClass 80059bd0: 00000000 nop 80059bd4: 2c420080 sltiu r2,r2,0x0080 80059bd8: 10400003 beq r2,r0,0x80059be8 80059bdc: 30630001 andi r3,r3,0x0001 # isSavingAsGuest = unit.Flags & ENTD_FLAG_JOIN_AS_GUEST # if ((unit.BaseClass >= 0x80) // Unit is generic 80059be0: 14a00002 bne r5,r0,0x80059bec # or (isGuest == 0)) 80059be4: 00000000 nop # { 80059be8: 00001821 addu r3,r0,r0 # isSavingAsGuest = 0; # } 80059bec: 92440002 lbu r4,0x0002(r18) # unit.PartyIndex 80059bf0: 306200ff andi r2,r3,0x00ff # isSavingAsGuest 80059bf4: 14400010 bne r2,r0,0x80059c38 80059bf8: 309000ff andi r16,r4,0x00ff # unit.PartyIndex # if (!isSavingAsGuest) { // Not saving as guest 80059bfc: 2482fff0 addiu r2,r4,-0x0010 80059c00: 2c420004 sltiu r2,r2,0x0004 80059c04: 1040000d beq r2,r0,0x80059c3c 80059c08: 2e020015 sltiu r2,r16,0x0015 # if ((unit.PartyIndex >= 16) and (unit.PartyIndex <= 19)) { // If already a guest 80059c0c: 0c0167f8 jal 0x80059fe0 # Remove Unit from Party (unit.PartyIndex); 80059c10: 00000000 nop 80059c14: 00002021 addu r4,r0,r0 80059c18: 0c016757 jal 0x80059d5c # freePartyIndex = Find Free Party Index (0, &zeroPtr); // Non-guest party index 80059c1c: 27a50010 addiu r5,r29,0x0010 80059c20: 00402021 addu r4,r2,r0 # freePartyIndex 80059c24: 2402ffff addiu r2,r0,-0x0001 80059c28: 10820045 beq r4,r2,0x80059d40 # if (freePartyIndex == -1) return -1; // If no slot found, return -1 80059c2c: 00808821 addu r17,r4,r0 # partyIndex = freePartyIndex 80059c30: 08016716 j 0x80059c58 # } 80059c34: 00000000 nop # } else { 80059c38: 2e020015 sltiu r2,r16,0x0015 80059c3c: 14400003 bne r2,r0,0x80059c4c 80059c40: 00002021 addu r4,r0,r0 # if (unit.PartyIndex >= 21) { // Unit not in party 80059c44: 08016706 j 0x80059c18 # freePartyIndex = Find Free Party Index (isSavingAsGuest, &zeroPtr); 80059c48: 00602021 addu r4,r3,r0 # if (freePartyIndex == -1) return -1; partyIndex = freePartyIndex; # } else { 80059c4c: 0c016757 jal 0x80059d5c # Find Free Party Index (0, &zeroPtr); // Value thrown away?? 80059c50: 27a50010 addiu r5,r29,0x0010 80059c54: 02008821 addu r17,r16,r0 # partyIndex = unit.PartyIndex # } # } 80059c58: 0c0166bc jal 0x80059af0 # partyUnit = Get Party Data Pointer (partyIndex); 80059c5c: 02202021 addu r4,r17,r0 80059c60: 92430000 lbu r3,0x0000(r18) # unit.BaseClass 80059c64: 00408021 addu r16,r2,r0 # partyUnit 80059c68: a2110001 sb r17,0x0001(r16) # partyUnit.UnitIndex = partyIndex 80059c6c: a2030000 sb r3,0x0000(r16) # partyUnit.BaseClass = unit.BaseClass 80059c70: 92420003 lbu r2,0x0003(r18) # unit.JobID 80059c74: 00000000 nop 80059c78: a2020002 sb r2,0x0002(r16) # partyUnit.JobID = unit.JobID 80059c7c: 2a220010 slti r2,r17,0x0010 80059c80: 14400007 bne r2,r0,0x80059ca0 # if (partyIndex >= 16) { 80059c84: 00000000 nop 80059c88: 92420004 lbu r2,0x0004(r18) # unit.TeamID 80059c8c: 00000000 nop 80059c90: a2020003 sb r2,0x0003(r16) # partyUnit.TeamID = unit.TeamID 80059c94: 92420006 lbu r2,0x0006(r18) # unit.Flags // "Gender" byte 80059c98: 0801672e j 0x80059cb8 80059c9c: 304200fb andi r2,r2,0x00fb # newFlags = unit.Flags & 0xfb // Masks out "Has ??? Stats" # } else { 80059ca0: 93a20010 lbu r2,0x0010(r29) # &zeroPtr (0) 80059ca4: 00000000 nop 80059ca8: a2020003 sb r2,0x0003(r16) # partyUnit.TeamID = 0 80059cac: 92420006 lbu r2,0x0006(r18) # unit.Flags // "Gender" byte 80059cb0: 00000000 nop 80059cb4: 304200fa andi r2,r2,0x00fa # newFlags = unit.Flags & 0xfb // Masks out "Has ??? Stats" and "Join as Guest" # } 80059cb8: a2020004 sb r2,0x0004(r16) # unit.Flags = newFlags 80059cbc: 26440013 addiu r4,r18,0x0013 # unit + 0x13 80059cc0: 26050007 addiu r5,r16,0x0007 # partyUnit + 7 80059cc4: 34060010 ori r6,r0,0x0010 # 16 80059cc8: 96430008 lhu r3,0x0008(r18) # unit.birthdayAndZodiac 80059ccc: 96420008 lhu r2,0x0008(r18) # unit.birthdayAndZodiac 80059cd0: 306301ff andi r3,r3,0x01ff # birthday = unit.birthdayAndZodiac & 0x01ff 80059cd4: 3042f000 andi r2,r2,0xf000 # zodiac = unit.birthdayAndZodiac & 0xf000 80059cd8: 00621825 or r3,r3,r2 # birthday | zodiac 80059cdc: 00031202 srl r2,r3,0x08 # (birthday | zodiac) >> 8 80059ce0: a2030005 sb r3,0x0005(r16) # partyUnit.Birthday = birthday | zodiac 80059ce4: 0c017895 jal 0x8005e254 # Store X Byte into Y (unit + 0x13, partyUnit + 7, 16); // memcpy with params reversed; first is src, second is dest 80059ce8: a2020006 sb r2,0x0006(r16) # partyUnit.Zodiac = (birthday | zodiac) >> 8 80059cec: 26440072 addiu r4,r18,0x0072 # unit + 0x72 80059cf0: 92420023 lbu r2,0x0023(r18) # unit.originalBrave 80059cf4: 26050019 addiu r5,r16,0x0019 # partyUnit + 0x19 80059cf8: a2020017 sb r2,0x0017(r16) # partyUnit.Brave = unit.originalBrave 80059cfc: 92420025 lbu r2,0x0025(r18) # unit.originalFaith 80059d00: 3406000f ori r6,r0,0x000f # 15 80059d04: 0c017895 jal 0x8005e254 # Store X Byte into Y (unit + 0x72, partyUnit + 0x19, 15); 80059d08: a2020018 sb r2,0x0018(r16) # partyUnit.Faith = unit.originalFaith 80059d0c: 26440096 addiu r4,r18,0x0096 # unit + 0x96 80059d10: 26050028 addiu r5,r16,0x0028 # partyUnit + 0x28 80059d14: 0c017895 jal 0x8005e254 # Store X Byte into Y (unit + 0x96, partyUnit + 0x28, 166); 80059d18: 340600a6 ori r6,r0,0x00a6 # 166 80059d1c: 9242016c lbu r2,0x016c(r18) # unit.UnitNameIDLowByte 80059d20: 00000000 nop 80059d24: a20200ce sb r2,0x00ce(r16) # partyUnit.UnitNameIDLowByte = unit.UnitNameIDLowByte 80059d28: 9643016c lhu r3,0x016c(r18) # unit.UnitNameID 80059d2c: 00001021 addu r2,r0,r0 80059d30: a20000d0 sb r0,0x00d0(r16) # partyUnit.Proposition = 0 80059d34: a20000d2 sb r0,0x00d2(r16) # partyUnit.0xd2 = 0 80059d38: 00031a02 srl r3,r3,0x08 # unit.UnitNameID >> 8 80059d3c: a20300cf sb r3,0x00cf(r16) # partyUnit.UnitNameIDHighByte = unit.UnitNameID >> 8 80059d40: 8fbf0024 lw r31,0x0024(r29) # return 0; 80059d44: 8fb20020 lw r18,0x0020(r29) 80059d48: 8fb1001c lw r17,0x001c(r29) 80059d4c: 8fb00018 lw r16,0x0018(r29) 80059d50: 27bd0028 addiu r29,r29,0x0028 80059d54: 03e00008 jr r31 80059d58: 00000000 nop