Skip to content

Commit

Permalink
Custom Object Construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Hurd committed Apr 7, 2019
1 parent a33cc83 commit 5f1c261
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 12 deletions.
23 changes: 15 additions & 8 deletions Python/test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import bl2sdk

def process_hook(caller, stack, result, function):
code = stack.Code
OfferingId = stack.popFString()
print("{} {}".format(OfferingId.Count, OfferingId.Max))
stack.Code = code
return True
# def process_hook(caller, stack, result, function):
# code = stack.Code
# OfferingId = stack.popFString()
# print("{} {}".format(OfferingId.Count, OfferingId.Max))
# stack.Code = code
# return True


bl2sdk.RemoveScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky")
bl2sdk.RegisterScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky", process_hook)
# bl2sdk.RemoveScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky")
# bl2sdk.RegisterScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky", process_hook)

for x in bl2sdk.UObject.FindObjectsContaining("Class "):
if not (x.bCooked):
print(x.GetFullName())

# x = bl2sdk.ConstructObject(bl2sdk.UObject.StaticClass())
# print(x)
12 changes: 11 additions & 1 deletion bl2-sdk/BL2-SDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ namespace BL2SDK

void initialize(wchar_t * exeBaseFolder)
{
//HookAntiDebug();
HookAntiDebug();
GameHooks::Initialize();
hookGame();
//InitializePackageFix();
Expand Down Expand Up @@ -408,6 +408,16 @@ namespace BL2SDK
SetIsLoadingUDKPackage(false);
};

UObject *ConstructObject(UClass* Class, UObject* InOuter, FName Name, unsigned int SetFlags, unsigned int InternalSetFlags, UObject* inTemplate, FOutputDevice *Error, void* InstanceGraph, int bAssumeTemplateIsArchetype)
{
if (!Error) {
Error = new FOutputDevice();
Error->VfTable = (void *)calloc(2, sizeof(void *));
((void **)Error->VfTable)[1] = (void *)&Logging::LogW;
}
return BL2SDK::pStaticConstructObject(Class, InOuter, Name, SetFlags, InternalSetFlags, inTemplate, Error, InstanceGraph, bAssumeTemplateIsArchetype);
};

UObject *GetEngine()
{
if (!engine)
Expand Down
4 changes: 3 additions & 1 deletion bl2-sdk/BL2-SDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace BL2SDK
typedef int (tUnrealEH)(unsigned int, struct _EXCEPTION_POINTERS*);
typedef void(__thiscall *tCallFunction) (UObject*, FFrame&, void* const, UFunction*);
typedef void(__thiscall *tFrameStep) (FFrame*, UObject*, void* const);
typedef UObject* (*tStaticConstructObject) (UClass* inClass, UObject* outer, FName name, unsigned int flags, UObject* inTemplate, FOutputDevice* error, UObject* root, void* unk);
// http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/StaticConstructObject_Internal/index.html
typedef UObject* (*tStaticConstructObject) (UClass* Class, UObject* InOuter, FName name, unsigned int SetFlags, unsigned int InternalSetFlags, UObject* InTemplate, FOutputDevice* Error, void* InstanceGraph, int bAssumeTemplateIsArchetype);
typedef UPackage* (*tLoadPackage) (UPackage* outer, const wchar_t* filename, DWORD flags);
typedef FArchive& (__thiscall *tByteOrderSerialize) (FArchive* Ar, void* V, int Length);

Expand All @@ -49,6 +50,7 @@ namespace BL2SDK
void initialize(wchar_t * exeBaseFolder/*LauncherStruct* args*/);
void cleanup();
void LoadPackage(const char* filename, DWORD flags = 0, bool force = false);
UObject *ConstructObject(UClass* Class, UObject* InOuter, FName Name, unsigned int SetFlags, unsigned int InternalSetFlags, UObject* inTemplate, FOutputDevice *Error, void* InstanceGraph, int bAssumeTemplateIsArchetype);
UObject *GetEngine();
}

Expand Down
1 change: 1 addition & 0 deletions bl2-sdk/CPythonInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ PYBIND11_EMBEDDED_MODULE(bl2sdk, m)
Export_pystes_TArray(m);
m.def("Log", [](std::string in) { Logging::Log(in.c_str(), in.length()); });
m.def("LoadPackage", &BL2SDK::LoadPackage);
m.def("ConstructObject", &BL2SDK::ConstructObject, "Construct Objects", py::arg("Class"), py::arg("InOuter") = BL2SDK::GetEngine()->Outer, py::arg("Name") = FName(), py::arg("SetFlags") = 0x201, py::arg("InternalSetFlags") = 0x00, py::arg("Template") = (UObject*)nullptr, py::arg("Error") = (FOutputDevice *)nullptr, py::arg("InstanceGraph") = (void*)nullptr, py::arg("bAssumeTemplateIsArchetype") = (int)0, py::return_value_policy::reference);
m.def("RegisterEngineHook", &RegisterEngineHook);
m.def("GetEngine", &BL2SDK::GetEngine, py::return_value_policy::reference);
m.def("RegisterScriptHook", &RegisterScriptHook);
Expand Down
9 changes: 8 additions & 1 deletion bl2-sdk/Core_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,14 @@ class UPackage : public UObject
class UClass : public UState
{
public:
unsigned char UnknownData00[0x100]; // 0x00D0 (0x0100) MISSED OFFSET
unsigned long bCooked : 1;
FPointer ClassAddReferencedObjects;
unsigned long ClassCastFlags;
FName ClassConfigName;
FPointer ClassConstructor;
UObject *ClassDefaultObject;
unsigned int ClassFlags;
unsigned char UnknownData00[0xD8]; // 0x00D0 (0x0100) MISSED OFFSET

private:
static UClass* pClassPointer;
Expand Down
7 changes: 7 additions & 0 deletions bl2-sdk/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ namespace Logging
}
}

void LogW(wchar_t *formatted, signed int length)
{
char *output = (char *)calloc(length + 1, sizeof(char));
wcstombs(output, formatted, length);
Log(output, 0);
}

void LogPy(const char* formatted)
{
Log(formatted, 0);
Expand Down
1 change: 1 addition & 0 deletions bl2-sdk/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Logging
{
void Log(const char* formatted, int length = 0);
void LogW(wchar_t *, int);
void LogPy(const char* formatted);
void LogF(const char *szFmt, ...);
void InitializeExtern();
Expand Down
2 changes: 2 additions & 0 deletions bl2-sdk/TypeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,9 @@ static std::map<std::string, const std::type_info *> uobject_type_map{
{"ChunkedList_Mirror", &typeid(FChunkedList_Mirror)},
{"ClanMaterialData", &typeid(FClanMaterialData)},
{"ClanSwitchData", &typeid(FClanSwitchData)},
#endif
{"Class", &typeid(UClass)},
#ifndef _DEBUG
{"ClassDropWeightValueResolver", &typeid(UClassDropWeightValueResolver)},
{"ClassModBalanceDefinition", &typeid(UClassModBalanceDefinition)},
{"ClassModDefinition", &typeid(UClassModDefinition)},
Expand Down
5 changes: 4 additions & 1 deletion bl2-sdk/gamedefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ struct FName
int Number;

public:
FName() {};
FName() {
Index = 0;
Number = 0;
};

public:
FName(const std::string& FindName)
Expand Down
2 changes: 2 additions & 0 deletions bl2-sdk/pydefs/Core_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ void Export_pystes_Core_classes(py::module &m)
.def_static("StaticClass", &UPackage::StaticClass, py::return_value_policy::reference)
;
py::class_< UClass, UState >(m, "UClass")
.def_property("bCooked", [](UClass &self) {return self.bCooked; }, [](UClass &self, bool value) {self.bCooked = value ? 1 : 0; })
.def_static("StaticClass", &UClass::StaticClass, py::return_value_policy::reference)
.def_readwrite("ClassFlags", &UClass::ClassFlags)
;

}

0 comments on commit 5f1c261

Please sign in to comment.