Skip to content
This repository was archived by the owner on Jan 1, 2025. It is now read-only.

Commit 5f1c261

Browse files
committed
Custom Object Construction
1 parent a33cc83 commit 5f1c261

10 files changed

+54
-12
lines changed

Python/test.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import bl2sdk
22

3-
def process_hook(caller, stack, result, function):
4-
code = stack.Code
5-
OfferingId = stack.popFString()
6-
print("{} {}".format(OfferingId.Count, OfferingId.Max))
7-
stack.Code = code
8-
return True
3+
# def process_hook(caller, stack, result, function):
4+
# code = stack.Code
5+
# OfferingId = stack.popFString()
6+
# print("{} {}".format(OfferingId.Count, OfferingId.Max))
7+
# stack.Code = code
8+
# return True
99

1010

11-
bl2sdk.RemoveScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky")
12-
bl2sdk.RegisterScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky", process_hook)
11+
# bl2sdk.RemoveScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky")
12+
# bl2sdk.RegisterScriptHook("Function WillowGame.MarketplaceGFxMovie.CreateContentItem", "Cheeky", process_hook)
13+
14+
for x in bl2sdk.UObject.FindObjectsContaining("Class "):
15+
if not (x.bCooked):
16+
print(x.GetFullName())
17+
18+
# x = bl2sdk.ConstructObject(bl2sdk.UObject.StaticClass())
19+
# print(x)

bl2-sdk/BL2-SDK.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ namespace BL2SDK
371371

372372
void initialize(wchar_t * exeBaseFolder)
373373
{
374-
//HookAntiDebug();
374+
HookAntiDebug();
375375
GameHooks::Initialize();
376376
hookGame();
377377
//InitializePackageFix();
@@ -408,6 +408,16 @@ namespace BL2SDK
408408
SetIsLoadingUDKPackage(false);
409409
};
410410

411+
UObject *ConstructObject(UClass* Class, UObject* InOuter, FName Name, unsigned int SetFlags, unsigned int InternalSetFlags, UObject* inTemplate, FOutputDevice *Error, void* InstanceGraph, int bAssumeTemplateIsArchetype)
412+
{
413+
if (!Error) {
414+
Error = new FOutputDevice();
415+
Error->VfTable = (void *)calloc(2, sizeof(void *));
416+
((void **)Error->VfTable)[1] = (void *)&Logging::LogW;
417+
}
418+
return BL2SDK::pStaticConstructObject(Class, InOuter, Name, SetFlags, InternalSetFlags, inTemplate, Error, InstanceGraph, bAssumeTemplateIsArchetype);
419+
};
420+
411421
UObject *GetEngine()
412422
{
413423
if (!engine)

bl2-sdk/BL2-SDK.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace BL2SDK
2424
typedef int (tUnrealEH)(unsigned int, struct _EXCEPTION_POINTERS*);
2525
typedef void(__thiscall *tCallFunction) (UObject*, FFrame&, void* const, UFunction*);
2626
typedef void(__thiscall *tFrameStep) (FFrame*, UObject*, void* const);
27-
typedef UObject* (*tStaticConstructObject) (UClass* inClass, UObject* outer, FName name, unsigned int flags, UObject* inTemplate, FOutputDevice* error, UObject* root, void* unk);
27+
// http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/StaticConstructObject_Internal/index.html
28+
typedef UObject* (*tStaticConstructObject) (UClass* Class, UObject* InOuter, FName name, unsigned int SetFlags, unsigned int InternalSetFlags, UObject* InTemplate, FOutputDevice* Error, void* InstanceGraph, int bAssumeTemplateIsArchetype);
2829
typedef UPackage* (*tLoadPackage) (UPackage* outer, const wchar_t* filename, DWORD flags);
2930
typedef FArchive& (__thiscall *tByteOrderSerialize) (FArchive* Ar, void* V, int Length);
3031

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

bl2-sdk/CPythonInterface.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ PYBIND11_EMBEDDED_MODULE(bl2sdk, m)
8282
Export_pystes_TArray(m);
8383
m.def("Log", [](std::string in) { Logging::Log(in.c_str(), in.length()); });
8484
m.def("LoadPackage", &BL2SDK::LoadPackage);
85+
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);
8586
m.def("RegisterEngineHook", &RegisterEngineHook);
8687
m.def("GetEngine", &BL2SDK::GetEngine, py::return_value_policy::reference);
8788
m.def("RegisterScriptHook", &RegisterScriptHook);

bl2-sdk/Core_classes.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,14 @@ class UPackage : public UObject
19811981
class UClass : public UState
19821982
{
19831983
public:
1984-
unsigned char UnknownData00[0x100]; // 0x00D0 (0x0100) MISSED OFFSET
1984+
unsigned long bCooked : 1;
1985+
FPointer ClassAddReferencedObjects;
1986+
unsigned long ClassCastFlags;
1987+
FName ClassConfigName;
1988+
FPointer ClassConstructor;
1989+
UObject *ClassDefaultObject;
1990+
unsigned int ClassFlags;
1991+
unsigned char UnknownData00[0xD8]; // 0x00D0 (0x0100) MISSED OFFSET
19851992

19861993
private:
19871994
static UClass* pClassPointer;

bl2-sdk/Logging.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ namespace Logging
6060
}
6161
}
6262

63+
void LogW(wchar_t *formatted, signed int length)
64+
{
65+
char *output = (char *)calloc(length + 1, sizeof(char));
66+
wcstombs(output, formatted, length);
67+
Log(output, 0);
68+
}
69+
6370
void LogPy(const char* formatted)
6471
{
6572
Log(formatted, 0);

bl2-sdk/Logging.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Logging
88
{
99
void Log(const char* formatted, int length = 0);
10+
void LogW(wchar_t *, int);
1011
void LogPy(const char* formatted);
1112
void LogF(const char *szFmt, ...);
1213
void InitializeExtern();

bl2-sdk/TypeMap.h

+2
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ static std::map<std::string, const std::type_info *> uobject_type_map{
873873
{"ChunkedList_Mirror", &typeid(FChunkedList_Mirror)},
874874
{"ClanMaterialData", &typeid(FClanMaterialData)},
875875
{"ClanSwitchData", &typeid(FClanSwitchData)},
876+
#endif
876877
{"Class", &typeid(UClass)},
878+
#ifndef _DEBUG
877879
{"ClassDropWeightValueResolver", &typeid(UClassDropWeightValueResolver)},
878880
{"ClassModBalanceDefinition", &typeid(UClassModBalanceDefinition)},
879881
{"ClassModDefinition", &typeid(UClassModDefinition)},

bl2-sdk/gamedefines.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ struct FName
6969
int Number;
7070

7171
public:
72-
FName() {};
72+
FName() {
73+
Index = 0;
74+
Number = 0;
75+
};
7376

7477
public:
7578
FName(const std::string& FindName)

bl2-sdk/pydefs/Core_classes.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ void Export_pystes_Core_classes(py::module &m)
562562
.def_static("StaticClass", &UPackage::StaticClass, py::return_value_policy::reference)
563563
;
564564
py::class_< UClass, UState >(m, "UClass")
565+
.def_property("bCooked", [](UClass &self) {return self.bCooked; }, [](UClass &self, bool value) {self.bCooked = value ? 1 : 0; })
565566
.def_static("StaticClass", &UClass::StaticClass, py::return_value_policy::reference)
567+
.def_readwrite("ClassFlags", &UClass::ClassFlags)
566568
;
567569

568570
}

0 commit comments

Comments
 (0)