feat: add some low level error handling
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "L2GameDataWrapper.h"
|
||||
#include "ProcessManipulation.h"
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@@ -23,40 +24,53 @@ namespace Interlude
|
||||
|
||||
(FARPROC&)__GetItemData = GetProcAddress(hModule, "?GetItemData@FL2GameData@@QAEPAVFL2ItemDataBase@@H@Z");
|
||||
(FARPROC&)__GetMSData = GetProcAddress(hModule, "?GetMSData@FL2GameData@@QAEPAUFL2MagicSkillData@@HH@Z");
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"FL2GameData hooks initialized");
|
||||
}
|
||||
|
||||
void L2GameDataWrapper::Restore()
|
||||
{
|
||||
restore(originalInitAddress);
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"FL2GameData hooks restored");
|
||||
}
|
||||
|
||||
//todo exception(?)
|
||||
FL2ItemDataBase* L2GameDataWrapper::GetItemData(int itemId) const
|
||||
{
|
||||
if (__GetItemData && _target) {
|
||||
return (*__GetItemData)(_target, itemId);
|
||||
__try {
|
||||
if (__GetItemData && _target) {
|
||||
return (*__GetItemData)(_target, itemId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"FL2GameData::GetItemData failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FL2MagicSkillData* L2GameDataWrapper::GetMSData(int skillId, int level) const
|
||||
{
|
||||
if (__GetMSData && _target) {
|
||||
return (*__GetMSData)(_target, skillId, level);
|
||||
__try {
|
||||
if (__GetMSData && _target) {
|
||||
return (*__GetMSData)(_target, skillId, level);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
throw CriticalRuntimeException(L"FL2GameData::GetMSData failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __fastcall L2GameDataWrapper::__Init_hook(L2GameData* This, int, int unk, int unk1)
|
||||
{
|
||||
if (_target == 0) {
|
||||
_target = This;
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"FL2GameData pointer {:#010x} obtained", (int)_target);
|
||||
|
||||
InjectLibrary::StopCurrentProcess();
|
||||
restore(originalInitAddress);
|
||||
InjectLibrary::StartCurrentProcess();
|
||||
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->Info(L"FL2GameData {:#010x} obtained", (int)_target);
|
||||
return (*__Init)(This, unk, unk1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user