Skip to content

Commit 974c749

Browse files
Merge pull request #4 from denisolenison/master
Rebalancing 2.0 + fixes
2 parents 7d2d65a + a60b907 commit 974c749

File tree

6 files changed

+105
-28
lines changed

6 files changed

+105
-28
lines changed

main.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class Mod : GenericMod {
104104
game->PrintMessage(L"[Notification] Correctly recentered player region.\n", 0, 255, 0);
105105
return 1;
106106
}
107-
108107
return 0;
109108
}
110109

@@ -236,8 +235,14 @@ class Mod : GenericMod {
236235
if (attacker->entity_data.hostility_type == cube::Creature::EntityBehaviour::Player ||
237236
attacker->entity_data.hostility_type == cube::Creature::EntityBehaviour::Pet)
238237
{
239-
240-
int xp_gain = GetCreatureLevel(creature) * (creature->entity_data.level + 1);
238+
int xp_gain = 100;
239+
240+
if (player->entity_data.level > GetCreatureLevel(creature)) {
241+
xp_gain = (int)std::roundf(100 * (creature->entity_data.level + 1) * std::powf(0.8f, player->entity_data.level - GetCreatureLevel(creature)));
242+
}
243+
else {
244+
xp_gain = (int)std::roundf(100 * (creature->entity_data.level + 1) * (1 + 0.15f * (GetCreatureLevel(creature) - player->entity_data.level)) * std::powf(1.05f, GetCreatureLevel(creature) - player->entity_data.level));
245+
}
241246

242247
if ((creature->entity_data.appearance.flags2 & (1 << (int)cube::Creature::AppearanceModifiers::IsBoss)) != 0)
243248
{
@@ -333,13 +338,13 @@ class Mod : GenericMod {
333338

334339
// ##### PLAYER ######
335340
// Defense
336-
m_PlayerScaling.insert_or_assign(STAT_TYPE::HEALTH, 5);
337-
m_PlayerScaling.insert_or_assign(STAT_TYPE::ARMOR, 1);
338-
m_PlayerScaling.insert_or_assign(STAT_TYPE::RESISTANCE, 1);
341+
m_PlayerScaling.insert_or_assign(STAT_TYPE::HEALTH, 1);
342+
m_PlayerScaling.insert_or_assign(STAT_TYPE::ARMOR, 0.2);
343+
m_PlayerScaling.insert_or_assign(STAT_TYPE::RESISTANCE, 0.2);
339344

340345
// Offense
341-
m_PlayerScaling.insert_or_assign(STAT_TYPE::ATK_POWER, 1);
342-
m_PlayerScaling.insert_or_assign(STAT_TYPE::SPELL_POWER, 1);
346+
m_PlayerScaling.insert_or_assign(STAT_TYPE::ATK_POWER, 0.2);
347+
m_PlayerScaling.insert_or_assign(STAT_TYPE::SPELL_POWER, 0.2);
343348
m_PlayerScaling.insert_or_assign(STAT_TYPE::CRIT, 0.0001f);
344349
m_PlayerScaling.insert_or_assign(STAT_TYPE::HASTE, 0.0001f);
345350

@@ -349,13 +354,13 @@ class Mod : GenericMod {
349354

350355
// ##### CREATURE ######
351356
// Defense
352-
m_CreatureScaling.insert_or_assign(STAT_TYPE::HEALTH, 20);
353-
m_CreatureScaling.insert_or_assign(STAT_TYPE::ARMOR, 0.1f);
354-
m_CreatureScaling.insert_or_assign(STAT_TYPE::RESISTANCE, 0.1f);
357+
m_CreatureScaling.insert_or_assign(STAT_TYPE::HEALTH, 0.9);
358+
m_CreatureScaling.insert_or_assign(STAT_TYPE::ARMOR, 0.7);
359+
m_CreatureScaling.insert_or_assign(STAT_TYPE::RESISTANCE, 0.7);
355360

356361
// Offense
357-
m_CreatureScaling.insert_or_assign(STAT_TYPE::ATK_POWER, 1);
358-
m_CreatureScaling.insert_or_assign(STAT_TYPE::SPELL_POWER, 1);
362+
m_CreatureScaling.insert_or_assign(STAT_TYPE::ATK_POWER, 0.8);
363+
m_CreatureScaling.insert_or_assign(STAT_TYPE::SPELL_POWER, 0.8);
359364
m_CreatureScaling.insert_or_assign(STAT_TYPE::CRIT, 0);
360365
m_CreatureScaling.insert_or_assign(STAT_TYPE::HASTE, 0);
361366

@@ -394,20 +399,19 @@ class Mod : GenericMod {
394399
if (creature->entity_data.hostility_type != cube::Creature::EntityBehaviour::Player &&
395400
creature->entity_data.hostility_type != cube::Creature::EntityBehaviour::Pet)
396401
{
397-
*stat /= creature->entity_data.level + 1;
398-
*stat += m_CreatureScaling.at(type) * (GetCreatureLevel(creature) - LEVELS_PER_REGION / 2);
399-
*stat *= creature->entity_data.level + 1;
402+
*stat *= m_CreatureScaling.at(type) * 0.5 * std::pow(2.7183, 0.2 * GetCreatureLevel(creature)) / 1.21 * std::pow(0.99, 1 + 0.07 * GetCreatureLevel(creature) * GetCreatureLevel(creature));
403+
400404
}
401405
}
402406

407+
403408
virtual void OnCreatureArmorCalculated(cube::Creature* creature, float* armor) override {
404409
ApplyStatBuff(creature, armor, STAT_TYPE::ARMOR);
405410
ApplyCreatureBuff(creature, armor, STAT_TYPE::ARMOR);
406411
}
407412

408413
virtual void OnCreatureCriticalCalculated(cube::Creature* creature, float* critical) override {
409414
ApplyStatBuff(creature, critical, STAT_TYPE::CRIT);
410-
ApplyCreatureBuff(creature, critical, STAT_TYPE::CRIT);
411415
}
412416

413417
virtual void OnCreatureAttackPowerCalculated(cube::Creature* creature, float* power) override {
@@ -422,7 +426,6 @@ class Mod : GenericMod {
422426

423427
virtual void OnCreatureHasteCalculated(cube::Creature* creature, float* haste) override {
424428
ApplyStatBuff(creature, haste, STAT_TYPE::HASTE);
425-
ApplyCreatureBuff(creature, haste, STAT_TYPE::HASTE);
426429
}
427430

428431
virtual void OnCreatureHPCalculated(cube::Creature* creature, float* hp) override {

src/GearScalingOverWrite.h

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,79 @@ extern "C" float GetGearScaling(cube::Item * item, cube::Creature* creature, int
2424
float base_res = ((base * 0.5f) / (float)0x20);
2525
float mod_modifier = (mod3 / 0x10624DD3) / 7.0f;
2626

27-
float X = 2;
27+
float X = 1.4;
2828
float Y = base_res + effective_rarity + mod_modifier;
2929

3030
float result = std::powf(X, Y);
3131

3232
cube::Game* game = cube::GetGame();
3333
if (game && creature->entity_data.hostility_type == cube::Creature::EntityBehaviour::Player)
3434
{
35-
result *= 1 + 0.05f * GetItemLevel(item);
35+
result *= 0.5 * std::pow(2.7183, 0.2 * GetItemLevel(item)) / 1.21 * std::pow(0.99, 1 + 0.07 * GetItemLevel(item) * GetItemLevel(item));
3636
}
3737
return result;
3838
}
3939

40+
extern "C" float GetOtherStatsRe(cube::Item * item, cube::Creature * creature)
41+
{
42+
IntVector2 region;
43+
if (creature->entity_data.hostility_type == 0)
44+
{
45+
region = creature->entity_data.current_region;
46+
}
47+
else
48+
{
49+
region = item->region;
50+
}
51+
52+
int mod = item->modifier;
53+
54+
int mod1 = mod ^ (mod << 0x0D);
55+
int mod2 = mod1 ^ (mod1 >> 0x11);
56+
int mod3 = mod2 ^ (mod2 << 0x05);
57+
58+
int effective_rarity = item->GetEffectiveRarity(&region);
59+
float mod_modifier = (mod3 / 0x10624DD3) / 7.0f;
60+
float randomizer = 2 * PyroRand(mod3) / 32768;
61+
62+
float X = 1.2;
63+
float Y = effective_rarity + mod_modifier;
64+
65+
float result = std::powf(X, Y);
66+
67+
68+
result *= 0.01f + 0.0016f * GetItemLevel(item);
69+
if (result > 0.2f) {
70+
result = std::log2f(result/0.2f)*0.2f + 0.2f;
71+
result *= randomizer;
72+
}
73+
74+
75+
76+
int category = item->category;
77+
78+
if (category < 3 || category > 9)
79+
{
80+
result *= 0;
81+
}
82+
83+
84+
return result;
85+
}
86+
87+
88+
extern "C" float GetHasteRe(cube::Item * item, cube::Creature * creature) {
89+
return GetOtherStatsRe(item, creature) * PyroRand(item->modifier + 0x157) / 32768;
90+
}
91+
92+
extern "C" float GetRegenRe(cube::Item * item, cube::Creature * creature) {
93+
return GetOtherStatsRe(item, creature) * PyroRand(item->GetSellingPrice() + 0x159) / 32768;
94+
}
95+
96+
extern "C" float GetCritRe(cube::Item * item, cube::Creature * creature) {
97+
return GetOtherStatsRe(item, creature) * PyroRand(item->GetBuyingPrice() + 0x161) / 32768;
98+
}
99+
40100
extern "C" float GearScaling(float x, float y, cube::Item* item)
41101
{
42102
float n = std::pow(x, y);
@@ -62,4 +122,7 @@ __attribute__((naked)) void ASM_OverwriteGearScaling() {
62122
void Setup_GearScalingOverwrite() {
63123
//WriteFarJMP(CWOffset(0x109D11), (void*)&ASM_OverwriteGearScaling);
64124
WriteFarJMP(CWOffset(0x109C50), GetGearScaling);
125+
WriteFarJMP(CWOffset(0x10A490), GetHasteRe); //haste
126+
WriteFarJMP(CWOffset(0x109F30), GetRegenRe); //regen
127+
WriteFarJMP(CWOffset(0x1090F0), GetCritRe); //critical
65128
}

src/LevelDisplayOverwrite.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ extern "C" void OverwriteItemName(cube::Item * item, std::wstring * string)
2929
{
3030
swprintf_s(buffer, 250, L"LV %.0f ", item_level);
3131
}
32-
3332
*string = buffer + *string;
3433
}
3534

3635
extern "C" void LevelDisplayOverwriteCreature(cube::Creature* creature, void* unk)
3736
{
3837
wchar_t buffer[250];
39-
4038
double item_level = GetCreatureLevel(creature);
4139

4240
if (item_level > 1e6)
@@ -51,7 +49,6 @@ extern "C" void LevelDisplayOverwriteCreature(cube::Creature* creature, void* un
5149
{
5250
swprintf_s(buffer, 250, L"LV %.0f ", item_level);
5351
}
54-
5552
PutText(unk, buffer);
5653
return;
5754
}

src/XPOverwrite.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
extern "C" int XP_Overwrite(int level)
66
{
77
//return (1050 * level - 50) / (level + 19);
8-
return 50 * std::powf(level + 1, 1.3f);
8+
//return 50 * std::powf(level + 1, 1.3f);
9+
return 5000 + 400*level;
910
}
1011

1112
__attribute__((naked)) void ASM_XP_Overwrite() {

src/utility.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ int GetItemLevel(cube::Item* item)
2727
return item->rarity;
2828
}
2929

30-
return 1 + LEVELS_PER_REGION * GetRegionDistance(item->region) + GetLevelVariation(item->modifier, LEVELS_PER_REGION);
30+
int res = 1 + LEVELS_PER_REGION * GetRegionDistance(item->region) + GetLevelVariation(item->modifier, LEVELS_PER_REGION);
31+
32+
if (res > 333) {
33+
res = 333;
34+
}
35+
36+
return res;
3137
}
3238

3339
int GetCreatureLevel(cube::Creature* creature)
@@ -58,7 +64,14 @@ int GetCreatureLevel(cube::Creature* creature)
5864
default:
5965
// Variation where packs of creatures have the same level
6066
//return (1 + 5 * distance) + GetLevelVariation(creature->entity_data.race * distance, 5);
61-
return (1 + LEVELS_PER_REGION * distance) + GetLevelVariation(creature->id, LEVELS_PER_REGION);
67+
68+
int res = (1 + LEVELS_PER_REGION * distance) + GetLevelVariation(creature->id, LEVELS_PER_REGION);
69+
if (res > 333) {
70+
res = 333;
71+
}
72+
73+
74+
return res;
6275
}
6376
}
6477

src/utility.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22
#include "cwsdk.h"
33

4-
#define LEVELS_PER_REGION 10
5-
#define LEVEL_EQUIPMENT_CAP 5
4+
#define LEVELS_PER_REGION 3
5+
#define LEVEL_EQUIPMENT_CAP 0
66

77
int GetRegionDistance(IntVector2 region);
88
int GetItemLevel(cube::Item* item);

0 commit comments

Comments
 (0)