Skip to content

Commit

Permalink
Merge branch dev
Browse files Browse the repository at this point in the history
  • Loading branch information
crosire committed Apr 5, 2016
2 parents 29113c0 + 9c7e3c6 commit 046a7bd
Show file tree
Hide file tree
Showing 30 changed files with 307 additions and 337 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ipch/
*.aps
*.cachefile
*.VC.db
*.opendb
*.opensdf
*.user
Expand Down
16 changes: 10 additions & 6 deletions source/core/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ namespace
namespace
{
bool sGameReloaded = false;
PVOID sMainFib = nullptr;
PVOID sScriptFib = nullptr;
PVOID sMainFib = nullptr, sScriptFib = nullptr;

void ScriptYield()
{
Expand All @@ -97,12 +96,17 @@ namespace
}
void ScriptMainSetup()
{
// Disable mplowrider2 car removing
const auto global2558120 = getGlobalPtr(2558120);
const auto version = getGameVersion();

if (global2558120 != nullptr)
if (version >= 18)
{
*global2558120 = 1;
// Disable mplowrider2 car removing
const auto global2558120 = getGlobalPtr(2558120);

if (global2558120 != nullptr)
{
*global2558120 = 1;
}
}

// Set up fibers
Expand Down
86 changes: 29 additions & 57 deletions source/core/Native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,26 @@ namespace GTA
{
nativeInit(_hash);

for each (InputArgument ^argument in _arguments)
for each (auto argument in _arguments)
{
nativePush64(argument->_data);
}

_result = nativeCall();
}

UINT64 _hash;
PUINT64 _result;
UINT64 _hash, *_result;
array<InputArgument ^> ^_arguments;
};

UINT64 ObjectToNative(System::Object ^value)
UINT64 ObjectToNative(Object ^value)
{
if (System::Object::ReferenceEquals(value, nullptr))
if (Object::ReferenceEquals(value, nullptr))
{
return 0;
}

System::Type ^type = value->GetType();
Type ^type = value->GetType();

// Fundamental types
if (type == Boolean::typeid)
Expand Down Expand Up @@ -102,75 +101,42 @@ namespace GTA
{
return static_cast<Model>(value).Hash;
}

if (type == Blip::typeid)
{
return static_cast<Blip ^>(value)->Handle;
}
if (type == Camera::typeid)
{
return static_cast<Camera ^>(value)->Handle;
}
if (type == Entity::typeid)
{
return static_cast<Entity ^>(value)->Handle;
}
if (type == Ped::typeid)
{
return static_cast<Ped ^>(value)->Handle;
}
if (type == PedGroup::typeid)
if (IHandleable::typeid->IsAssignableFrom(type))
{
return static_cast<PedGroup ^>(value)->Handle;
}
if (type == Player::typeid)
{
return static_cast<Player ^>(value)->Handle;
}
if (type == Prop::typeid)
{
return static_cast<Prop ^>(value)->Handle;
}
if (type == Rope::typeid)
{
return static_cast<Rope ^>(value)->Handle;
}
if (type == Vehicle::typeid)
{
return static_cast<Vehicle ^>(value)->Handle;
return safe_cast<IHandleable ^>(value)->Handle;
}

throw gcnew InvalidCastException(String::Concat("Unable to cast object of type '", type->FullName, "' to native value"));
}
System::Object ^ObjectFromNative(System::Type ^type, PUINT64 value)
Object ^ObjectFromNative(Type ^type, UINT64 *value)
{
// Fundamental types
if (type == Boolean::typeid)
{
return *reinterpret_cast<int *>(value) != 0;
return *reinterpret_cast<const int *>(value) != 0;
}
if (type == Int32::typeid)
{
return *reinterpret_cast<int *>(value);
return *reinterpret_cast<const int *>(value);
}
if (type == UInt32::typeid)
{
return *reinterpret_cast<unsigned int *>(value);
return *reinterpret_cast<const unsigned int *>(value);
}
if (type == Single::typeid)
{
return *reinterpret_cast<float *>(value);
return *reinterpret_cast<const float *>(value);
}
if (type == Double::typeid)
{
return static_cast<double>(*reinterpret_cast<float *>(value));
return static_cast<double>(*reinterpret_cast<const float *>(value));
}
if (type == String::typeid)
{
if (*value != 0)
{
const int size = static_cast<int>(strlen(reinterpret_cast<const char *>(*value)));
array<Byte> ^bytes = gcnew array<Byte>(size);
const auto size = static_cast<int>(strlen(reinterpret_cast<const char *>(*value)));
const auto bytes = gcnew array<Byte>(size);

Runtime::InteropServices::Marshal::Copy(static_cast<IntPtr>(static_cast<Int64>(*value)), bytes, 0, size);

Expand All @@ -182,7 +148,7 @@ namespace GTA
}
}

#pragma pack(push, 1)
#pragma pack(push, 1)
struct NativeVector3
{
float x;
Expand All @@ -192,16 +158,18 @@ namespace GTA
float z;
DWORD _paddingz;
};
#pragma pack(pop)
#pragma pack(pop)

// Math types
if (type == Math::Vector2::typeid)
{
return gcnew Math::Vector2(reinterpret_cast<NativeVector3 *>(value)->x, reinterpret_cast<NativeVector3 *>(value)->y);
const auto vec = reinterpret_cast<NativeVector3 *>(value);
return gcnew Math::Vector2(vec->x, vec->y);
}
if (type == Math::Vector3::typeid)
{
return gcnew Math::Vector3(reinterpret_cast<NativeVector3 *>(value)->x, reinterpret_cast<NativeVector3 *>(value)->y, reinterpret_cast<NativeVector3 *>(value)->z);
const auto vec = reinterpret_cast<NativeVector3 *>(value);
return gcnew Math::Vector3(vec->x, vec->y, vec->z);
}

const int handle = *reinterpret_cast<int *>(value);
Expand Down Expand Up @@ -261,16 +229,20 @@ namespace GTA
}
}

InputArgument::InputArgument(System::Object ^value) : _data(ObjectToNative(value))
InputArgument::InputArgument(Object ^value) : _data(ObjectToNative(value))
{
}
OutputArgument::OutputArgument() : _storage(new unsigned char[24]()), InputArgument(IntPtr(_storage))
{
}
OutputArgument::OutputArgument(System::Object ^value) : OutputArgument()
OutputArgument::OutputArgument(Object ^value) : OutputArgument()
{
*reinterpret_cast<UINT64 *>(_storage) = ObjectToNative(value);
}
OutputArgument::~OutputArgument()
{
this->!OutputArgument();
}
OutputArgument::!OutputArgument()
{
delete[] _storage;
Expand All @@ -279,7 +251,7 @@ namespace GTA
generic <typename T>
T OutputArgument::GetResult()
{
return static_cast<T>(ObjectFromNative(T::typeid, reinterpret_cast<PUINT64>(_data)));
return static_cast<T>(ObjectFromNative(T::typeid, reinterpret_cast<UINT64 *>(_data)));
}

generic <typename T>
Expand All @@ -294,7 +266,7 @@ namespace GTA
generic <typename T>
T Function::Call(UInt64 hash, ... array<InputArgument ^> ^arguments)
{
NativeTask ^task = gcnew NativeTask();
const auto task = gcnew NativeTask();
task->_hash = hash;
task->_arguments = arguments;

Expand Down
Loading

0 comments on commit 046a7bd

Please sign in to comment.