Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBitz committed Aug 22, 2021
2 parents 4d19d1c + 472e35b commit a6073d6
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 13 deletions.
7 changes: 7 additions & 0 deletions README.CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ This is a compilations of ASM/editions for vSRO (1.188) that you'll need to chan
00797E21 | 3C 0A | cmp al,A | Unlock action
```

### SERVER_BEGINNER_MARK_LEVEL_MAX

Fill with NOPs the following instruction to show the beginner mark always.
```
009DED3D | 0F84 9E000000 | je sro_client.9DEDE1 |
```

### RACE_CH_TOTAL_MASTERIES

0x14A = 330, 0xDC = 220
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ VALUES
);
```

19. Reduces health and/or mana points from player
```sql
INSERT INTO [SRO_VT_SHARD].[dbo].[_ExeGameServer]
(
Action_ID,
CharName16,
Param02, -- HP reduced
Param02 -- MP reduced
)
VALUES
(
19,
'JellyBitz',
5000, -- Reducing HP only
0
);
```


### Action Result Code

Expand Down
49 changes: 45 additions & 4 deletions vSRO-GameServer/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "Utils/Memory/Process.h"
#include "Utils/Memory/hook.h"
#pragma warning(disable:4244) // Bitwise operations warnings
// ASM injection
#include "AsmEdition.h"

/// Static stuffs
bool AppManager::m_IsInitialized;
Expand Down Expand Up @@ -50,6 +52,7 @@ void AppManager::InitConfigFile()
// Memory
ini.SetLongValue("Server", "LEVEL_MAX", 110, "; Maximum level that can be reached on server");
ini.SetLongValue("Server", "STALL_PRICE_LIMIT", 9999999999, "; Maximum price that can be stalled");
ini.SetLongValue("Server", "PARTY_LEVEL_MIN", 5, "; Minimum level to create a party group");
ini.SetLongValue("Server", "PARTY_MOB_MEMBERS_REQUIRED", 2, "; Party members required to find monsters party type");
ini.SetLongValue("Server", "PARTY_MOB_SPAWN_PROBABILITY", 50, "; % Probability for party mob spawns");
ini.SetLongValue("Server", "PK_LEVEL_REQUIRED", 20, "; Level required to kill other player");
Expand All @@ -60,6 +63,7 @@ void AppManager::InitConfigFile()
ini.SetLongValue("Server", "BEGINNER_MARK_LEVEL_MAX", 19, "; Maximum level to show the beginner mark");
ini.SetLongValue("Job", "LEVEL_MAX", 7, "; Maximum level that can be reached on job suit");
ini.SetBoolValue("Job", "DISABLE_MOB_SPAWN", false, "; Disable Thief/Hunter monster spawn while trading");
ini.SetLongValue("Job", "TEMPLE_LEVEL", 105, "; Minimum level to enter the Temple Area");
ini.SetLongValue("Race", "CH_TOTAL_MASTERIES", 330, "; Masteries amount Chinese will obtain");
ini.SetLongValue("Guild", "MEMBERS_LIMIT_LEVEL1", 15, "; Guild members capacity at level 1");
ini.SetLongValue("Guild", "MEMBERS_LIMIT_LEVEL2", 20, "; Guild members capacity at level 2");
Expand Down Expand Up @@ -89,6 +93,7 @@ void AppManager::InitConfigFile()
ini.SetBoolValue("Fix", "DISABLE_MSGBOX_SILK_GOLD_PRICE", true, "; Disable messages about \"register silk/gold price.\"");
ini.SetBoolValue("Fix", "EXCHANGE_ATTACK_CANCEL", true, "; Remove attack cancel when player exchanges");
ini.SetBoolValue("Fix", "EXPLOIT_INVISIBLE_INVINCIBLE", true, "; Cancel exploit sent from client (0x70A7)");
ini.SetBoolValue("Fix", "GUILD_POINTS", true, "; Prevents negative values on guild points");
// App
ini.SetBoolValue("App", "DEBUG_CONSOLE", true, "; Attach debug console");
// Save it
Expand Down Expand Up @@ -118,7 +123,7 @@ void AppManager::InitHooks()
CSimpleIniA ini;
ini.LoadFile("vSRO-GameServer.ini");

// Uniques
// Fixes
if (ini.GetBoolValue("Fix","UNIQUE_LOGS",true))
{
// Create connection string
Expand All @@ -131,16 +136,26 @@ void AppManager::InitHooks()

if (m_dbUniqueLog.sqlConn.Open((SQLWCHAR*)connString.str().c_str()) && m_dbUniqueLog.sqlCmd.Open(m_dbUniqueLog.sqlConn))
{
printf(" - FIX_UNIQUE_LOGS\r\n");
if (replaceOffset(0x00414DB0, addr_from_this(&AppManager::OnUniqueSpawnMsg)))
{
std::cout << " - OnUniqueSpawnMsg" << std::endl;
std::cout << " - OnUniqueSpawnMsg" << std::endl;
}
if (replaceOffset(0x00414BA9, addr_from_this(&AppManager::OnUniqueKilledMsg)))
{
std::cout << " - OnUniqueKilledMsg" << std::endl;
std::cout << " - OnUniqueKilledMsg" << std::endl;
}
}
}
if (ini.GetBoolValue("Fix", "GUILD_POINTS", true))
{
printf(" - FIX_GUILD_POINTS\r\n");
// Redirect code flow to DLL
if (placeHook(0x005C4135, addr_from_this(&AsmEdition::OnDonateGuildPoints)))
{
std::cout << " - OnDonateGuildPoints" << std::endl;
}
}
}
void AppManager::OnUniqueSpawnMsg(uint32_t LogType, const char* Message, const char* UniqueCodeName, uint16_t RegionId, uint32_t unk01, uint32_t unk02)
{
Expand Down Expand Up @@ -216,6 +231,12 @@ void AppManager::InitPatchValues()
WriteMemoryValue<uint32_t>(0x004F7746 + 4, newValue);
}
}
if(ReadMemoryValue<uint8_t>(0x00513FEC + 1, byteValue))
{
uint8_t newValue = ini.GetLongValue("Server", "PARTY_LEVEL_MIN", 5);
printf(" - SERVER_PARTY_LEVEL_MIN (%d) -> (%d)\r\n", byteValue, newValue);
WriteMemoryValue<uint8_t>(0x00513FEC + 1, newValue);
}
if(ReadMemoryValue<uint8_t>(0x00558F20 + 4, byteValue))
{
uint8_t newValue = ini.GetLongValue("Server", "PARTY_MOB_MEMBERS_REQUIRED", 2);
Expand Down Expand Up @@ -278,6 +299,13 @@ void AppManager::InitPatchValues()
printf(" - JOB_DISABLE_MOB_SPAWN\r\n");
WriteMemoryValue<uint16_t>(0x0060C4AB, 0xC031); // mov eax,esi -> xor eax,eax
}
if (ReadMemoryValue<uint8_t>(0x0051AE71 + 1, byteValue))
{
uint8_t newValue = ini.GetLongValue("Job", "TEMPLE_LEVEL", 105);
printf(" - JOB_TEMPLE_LEVEL (%d) -> (%d)\r\n", byteValue, newValue);
WriteMemoryValue<uint8_t>(0x0051AE71 + 1, newValue);
WriteMemoryValue<uint8_t>(0x0051ABE8 + 1, newValue);
}

// Race
if (ReadMemoryValue<uint32_t>(0x0059C5E6 + 1, uintValue))
Expand Down Expand Up @@ -457,7 +485,7 @@ void AppManager::InitPatchValues()
WriteMemoryValue<uint8_t>(0x0066917A + 4, newValue);
}

// Fixes
// Fix
if (ReadMemoryValue<uint32_t>(0x004744BC + 1, uintValue))
{
uint32_t newValue = ini.GetLongValue("Fix", "AGENT_SERVER_CAPACITY", 1000);
Expand Down Expand Up @@ -899,6 +927,19 @@ DWORD WINAPI AppManager::DatabaseFetchThread()
actionResult = FETCH_ACTION_STATE::CHARNAME_NOT_FOUND;
}
} break;
case 19: // Reduce HP/MP from player
{
SQLINTEGER cParam02, cParam03, cParam04;
if (m_dbLink.sqlCmd.GetData(5, SQL_C_LONG, &cParam02, 0, NULL)
&& m_dbLink.sqlCmd.GetData(6, SQL_C_LONG, &cParam03, 0, NULL))
{
CGObjPC* player = CGObjManager::GetObjPCByCharName16(cCharName);
if (player)
player->ReduceHPMP(cParam02, cParam03, true);
else
actionResult = FETCH_ACTION_STATE::CHARNAME_NOT_FOUND;
}
} break;
case 3312: // For testing references
{
CGObjPC* player = CGObjManager::GetObjPCByCharName16(cCharName);
Expand Down
26 changes: 26 additions & 0 deletions vSRO-GameServer/AsmEdition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Windows.h>
#pragma once

// Direct ASM injection
namespace AsmEdition
{
// Jump back to the code flow from donating guild points
static DWORD jmpAddr_DonateGP = 0x005C413A;
// Handler to catch guild point increasing hook and edit directly with asm
static _declspec(naked) void OnDonateGuildPoints()
{
// Rebuild asm
__asm
{
mov ecx, dword ptr[eax + 0x3c] // rebuild
add ecx, esi // rebuild
cmp ecx, 0x7FFFFFFF // compare ecx with int.MaxValue
jbe _continue // go to _continue if ecx <= int.MaxValue
mov ecx, 0x7FFFFFFF // set ecx as int.MaxValue
jmp _continue // go to _continue
}
// Contine code flow
_continue:
__asm jmp jmpAddr_DonateGP;
}
}
14 changes: 12 additions & 2 deletions vSRO-GameServer/Silkroad/Object/CGObjPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ void CGObjPC::UpdateSP(int32_t Offset)
{
CallVirtual<void(__thiscall*)(CGObjPC*, int32_t, int8_t)>(this, 93)(this, Offset, 1);
}
void CGObjPC::UpdateHPMP(int32_t Health, int32_t Mana, uint16_t DisplayEffectType)
void CGObjPC::ReduceHPMP(uint32_t Health, uint32_t Mana, bool ShowEffect)
{
CallVirtual<void(__thiscall*)(CGObjPC*, int32_t, int32_t, uint16_t)>(this, 194)(this, Health, Mana, DisplayEffectType);
// Check if player will die by health reduction
bool died = Health > m_CInstancePC->Health;
if (died)
{
Health = m_CInstancePC->Health;
Mana = m_CInstancePC->Mana;
}
CallVirtual<void(__thiscall*)(CGObjPC*, uint32_t, uint32_t, uint16_t)>(this, 194)(this, Health, Mana, ShowEffect ? 1024 : 0);
// Set dead status
if (died)
SetLifeState(false);
}
void CGObjPC::UpdatePVPCapeType(uint8_t CapeType)
{
Expand Down
4 changes: 2 additions & 2 deletions vSRO-GameServer/Silkroad/Object/CGObjPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CGObjPC : public CGObjChar
void UpdateExperience(int64_t ExpOffset);
// Add skill experience
void AddSPExperience(uint32_t SPExpOffset);
// Updates the HP and MP
void UpdateHPMP(int32_t Health, int32_t Mana, uint16_t DisplayEffectType);
// Reduces health and/or mana points. If health reduced exceeds the current amount, the player will die
void ReduceHPMP(uint32_t Health, uint32_t Mana, bool ShowEffect);
// Updates the cape state from PVP
void UpdatePVPCapeType(uint8_t CapeType);
// Moves the player to the map location. Return success
Expand Down
10 changes: 7 additions & 3 deletions vSRO-GameServer/Silkroad/Object/CInstancePC.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>

// Contains the basic informacion from player character
class CInstancePC
{
public:
Expand All @@ -9,7 +10,8 @@ class CInstancePC
char pad_0014[4]; //0x0014
uint32_t RefObjCharPtr; //0x0018
char pad_001C[4]; //0x001C
uint32_t CharID; //0x0020
// ID to identify the player from database
uint32_t CharID;
char pad_0024[4]; //0x0024
uint32_t ModelID; //0x0028
char pad_002C[4]; //0x002C
Expand All @@ -27,8 +29,10 @@ class CInstancePC
uint32_t RemainSkillPoint; //0x0080
uint32_t RemainStatPoint; //0x0084
char pad_0088[4]; //0x0088
uint32_t CurHealth; //0x008C
uint32_t CurMana; //0x0090
// Current health points
uint32_t Health;
// Current mana points
uint32_t Mana;
uint32_t RegionID; //0x0094
float PosX; //0x0098
float PosY; //0x009C
Expand Down
1 change: 1 addition & 0 deletions vSRO-GameServer/vSRO-GameServer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="AppManager.h" />
<ClInclude Include="AsmEdition.h" />
<ClInclude Include="Silkroad\Text\GString.h" />
<ClInclude Include="Silkroad\Object\CInstancePC.h" />
<ClInclude Include="resource.h" />
Expand Down
30 changes: 28 additions & 2 deletions vSRO-ShardManager/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#include <Windows.h>
#include <iostream>
// Utils
#include "Utils/Memory/Process.h"
#include "Utils/IO/SimpleIni.h"
#include "Utils/Memory/Process.h"
#include "Utils/Memory/hook.h"
#pragma warning(disable:4244) // Bitwise operations warnings
// ASM injection
#include "AsmEdition.h"

/// Static stuffs
bool AppManager::m_IsInitialized;

void AppManager::Initialize()
{
if (!m_IsInitialized)
Expand All @@ -35,6 +37,7 @@ void AppManager::InitConfigFile()
ini.SetLongValue("Event", "CTF_PARTICIPANS_MIN", 8, "; Minimum participants required to start Capture The Flag");
ini.SetLongValue("Event", "BA_PARTICIPANS_MIN", 8, "; Minimum participants required to start Battle Arena");
ini.SetBoolValue("Fix", "PARTY_MATCH_1HOUR_DC", true, "; Fix disconnect when party takes more than 1 hour on party match");
ini.SetBoolValue("Fix", "GUILD_POINTS", true, "; Prevents negative values on guild points");
// App
ini.SetBoolValue("App", "DEBUG_CONSOLE", true, "; Attach debug console");
// Save it
Expand All @@ -58,7 +61,30 @@ void AppManager::InitDebugConsole()
}
void AppManager::InitHooks()
{
std::cout << " * Initializing hooks..." << std::endl;

// Load file
CSimpleIniA ini;
ini.LoadFile("vSRO-GameServer.ini");

// Fix
if (ini.GetBoolValue("Fix", "GUILD_POINTS", true))
{
printf(" - FIX_GUILD_POINTS\r\n");
// Redirect code flow to DLL
if (placeHook(0x004364EE, addr_from_this(&AsmEdition::OnDonateGuildPoints)))
{
std::cout << " - OnDonateGuildPoints" << std::endl;
}
if (placeHook(0x00438B68, addr_from_this(&AsmEdition::OnDonateGuildPointsErrorCode)))
{
std::cout << " - OnDonateGuildPointsErrorCode" << addr_from_this(&AsmEdition::OnDonateGuildPointsErrorCode) << std::endl;
}
if (placeHook(0x0043A9F6, addr_from_this(&AsmEdition::OnDonateGuildPointsErrorMsg)))
{
std::cout << " - OnDonateGuildPointsErrorMsg" << addr_from_this(&AsmEdition::OnDonateGuildPointsErrorMsg) << std::endl;
}
}
}
void AppManager::InitPatchValues()
{
Expand Down
Loading

0 comments on commit a6073d6

Please sign in to comment.