Skip to content

Instantly share code, notes, and snippets.

@leoetlino
Last active February 10, 2019 21:31
Show Gist options
  • Save leoetlino/877cb2bdb53ad08cd3c28d716a1fc8c6 to your computer and use it in GitHub Desktop.
Save leoetlino/877cb2bdb53ad08cd3c28d716a1fc8c6 to your computer and use it in GitHub Desktop.
bool __fastcall determineWeaponBonus(_DWORD *a1, WeaponModifierRanges *ranges) // 0x71002DFB9C
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
bonus = WeaponModifierRanges::getRandomBonus(ranges);
if ( bonus == WeaponBonus_None )
return 0;
if ( ranges->field_31 )
*a1 |= 0x80000000;
if ( (signed int)bonus <= 0x3F )
{
switch ( bonus )
{
case WeaponBonus_AddAtk:
v6 = ranges->addAtkMin;
v5 = ranges->addAtkMax;
v7 = 1;
v8 = (sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)(unsigned int)(1 - v6 + v5) >> 0x20)
+ v6;
if ( v8 < 1 )
return v7;
v9 = *a1 & 0x80000000 | 1;
goto LABEL_16;
case WeaponBonus_AddLife:
v13 = ranges->addLifeMin;
v12 = ranges->addLifeMax;
v7 = 1;
v8 = (sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)(unsigned int)(1 - v13 + v12) >> 0x20)
+ v13;
if ( v8 < 1 )
return v7;
v9 = *a1 & 0x80000000 | 2;
goto LABEL_16;
case WeaponBonus_AddThrow:
v14 = ranges->addThrowMin;
v15 = ranges->addThrowMax - v14;
v16 = v14
+ (float)(v15
* (float)(COERCE_FLOAT((sead::Random::getU32(sead::GlobalRandom::sInstance) >> 9) | 0x3F800000)
+ -1.0));
if ( v16 <= 0.0 )
return 1;
v17 = *a1 & 0x80000000 | 8;
goto LABEL_27;
case WeaponBonus_AddSpreadFire:
*a1 = *a1 & 0x80000000 | 0x10;
v8 = 5;
goto LABEL_20;
default:
goto def_71002DFBFC;
}
goto def_71002DFBFC;
}
if ( bonus == WeaponBonus_AddRapidFire )
{
v18 = ranges->addRapidFireMin;
v19 = ranges->addRapidFireMax - v18;
v16 = v18
+ (float)(v19
* (float)(COERCE_FLOAT((sead::Random::getU32(sead::GlobalRandom::sInstance) >> 9) | 0x3F800000) + -1.0));
if ( v16 <= 0.0 )
return 1;
v17 = *a1 & 0x80000000 | 0x40;
LABEL_27:
*a1 = v17;
a1[1] = (signed int)(float)(v16 * 1000.0);
return 1;
}
if ( bonus == WeaponBonus_AddSurfMaster )
{
if ( !GlobalParameter::sInstance )
return 1;
v20 = GlobalParameter::sInstance->globalParam;
if ( !v20 )
return 1;
v16 = v20->shieldSurfMasterFrictionRatio.value;
if ( v16 <= 0.0 )
return 1;
v17 = *a1 & 0x80000000 | 0x80;
goto LABEL_27;
}
if ( bonus != 0x100 )
{
def_71002DFBFC:
v7 = 1;
*a1 = bonus;
a1[1] = 0;
return v7;
}
v11 = ranges->addGuardMin;
v10 = ranges->addGuardMax;
v7 = 1;
v8 = (sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)(unsigned int)(1 - v11 + v10) >> 0x20)
+ v11;
if ( v8 < 1 )
return v7;
v9 = *a1 & 0x80000000 | 0x100;
LABEL_16:
*a1 = v9;
LABEL_20:
a1[1] = v8;
return 1;
}
WeaponBonus __fastcall WeaponModifierRanges::getRandomBonus(WeaponModifierRanges *this) // 0x71002F1D68
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
if ( this->addAtkMin <= 0 )
counter = 1;
else
counter = 2;
bonus = this->addAtkMin > 0;
if ( this->addLifeMin >= 1 )
{
v4 = sead::Random::getU32(sead::GlobalRandom::sInstance);
if ( !(v4 * (unsigned __int64)counter & 0x300000000LL) )
bonus = 2;
if ( !(v4 * (unsigned __int64)counter & 0x300000000LL) )
++counter;
}
if ( this->addCrit )
{
v5 = sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter;
v6 = v5 >> 0x20 == 0;
v7 = v5 >> 0x20 == 0;
if ( v6 )
bonus = 4;
counter += v7;
}
if ( this->addGuardMin >= 1 )
{
v8 = sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter;
v6 = v8 >> 0x20 == 0;
v9 = v8 >> 0x20 == 0;
if ( v6 )
bonus = 0x100;
counter += v9;
}
if ( this->addThrowMin != 1.0 || this->addThrowMax != 1.0 )
{
v10 = sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter;
v6 = v10 >> 0x20 == 0;
v11 = v10 >> 0x20 == 0;
if ( v6 )
bonus = 8;
counter += v11;
}
if ( this->addSpreadFire )
{
v12 = sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter;
v6 = v12 >> 0x20 == 0;
v13 = v12 >> 0x20 == 0;
if ( v6 )
bonus = 0x10;
counter += v13;
}
if ( this->addZoomRapid )
{
v14 = sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter;
v6 = v14 >> 0x20 == 0;
v15 = v14 >> 0x20 == 0;
if ( v6 )
bonus = 0x20;
counter += v15;
}
if ( this->addRapidFireMin != 1.0 || this->addRapidFireMax != 1.0 )
{
v16 = sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter;
v6 = v16 >> 0x20 == 0;
v17 = v16 >> 0x20 == 0;
if ( v6 )
bonus = 0x40;
counter += v17;
}
if ( !this->addSurfMaster )
return bonus;
if ( sead::Random::getU32(sead::GlobalRandom::sInstance) * (unsigned __int64)counter >> 0x20 )
return bonus;
return 0x80;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment