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

Commit 31000de

Browse files
committed
Add ParticleSystem, fix FString, add GetEngine
1 parent e360f55 commit 31000de

9 files changed

+146
-62
lines changed

Python/commander.py

-59
This file was deleted.

Python/commander_wannabe.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import bl2sdk
2+
import math
3+
4+
class Controller():
5+
CurrentKeys = set()
6+
isThirdPerson = False
7+
8+
def process_input(self, caller, function, parms, result):
9+
ControllerId = parms.popInt()
10+
Key = parms.popFName()
11+
EventType = parms.popByte()
12+
name = Key.GetName()
13+
if EventType == 0:
14+
self.CurrentKeys.add(name)
15+
if 'LeftControl' in self.CurrentKeys or 'RightControl' in self.CurrentKeys:
16+
if name == 'Up':
17+
move_forward_backward(100)
18+
if name == 'Down':
19+
move_forward_backward(-100)
20+
if name == 'Left':
21+
move_left_right(-100)
22+
if name == 'Right':
23+
move_left_right(100)
24+
if 'NumPadNine' == name:
25+
self.toggle_third_person()
26+
elif EventType == 1 and name in self.CurrentKeys:
27+
self.CurrentKeys.remove(name)
28+
29+
def toggle_third_person(self):
30+
engine = bl2sdk.GetEngine()
31+
pc = engine.GamePlayers[0].Actor
32+
new_mode = 'camera ' + ('1st' if self.isThirdPerson else '3rd')
33+
pc.ConsoleCommand(bl2sdk.FString(new_mode), 0)
34+
print(new_mode)
35+
self.isThirdPerson = not self.isThirdPerson
36+
37+
def convert_rotation(rotation):
38+
conversion = 65535.0 / math.pi / 2.0
39+
degree_pitch = rotation.Pitch / conversion
40+
degree_yaw = rotation.Yaw / conversion
41+
return degree_pitch, degree_yaw
42+
43+
def move_forward_backward(distance):
44+
engine = bl2sdk.GetEngine()
45+
pawn = engine.GamePlayers[0].Actor.AcknowledgedPawn
46+
position = pawn.Location
47+
pitch, yaw = convert_rotation(pawn.Rotation)
48+
position.Z += math.sin(pitch) * distance
49+
position.X += math.cos(yaw) * math.cos(pitch) * distance
50+
position.Y += math.sin(yaw) * math.cos(pitch) * distance
51+
52+
def move_left_right(distance):
53+
engine = bl2sdk.GetEngine()
54+
pawn = engine.GamePlayers[0].Actor.AcknowledgedPawn
55+
position = pawn.Location
56+
pitch, yaw = convert_rotation(pawn.Rotation)
57+
position.X += math.cos(yaw + math.pi / 2) * distance
58+
position.Y += math.sin(yaw + math.pi / 2) * distance
59+
60+
61+
bl2sdk.RemoveEngineHook("Function WillowGame.WillowGameViewportClient.InputKey", "DoCommanderThings")
62+
bl2sdk.RegisterEngineHook("Function WillowGame.WillowGameViewportClient.InputKey", "DoCommanderThings", Controller().process_input)
63+
64+
65+
# def noclip():
66+
# pc = engine.GamePlayers[0].Actor
67+
# pawn = pc.AcknowledgedPawn
68+
# pc.WorldInfo.Game.AllowCheats(pc)
69+
# if pc.bCheatFlying:
70+
# pawn.Physics = 0x1
71+
# pawn.PhysicsVolume.FluidFriction = 0.3
72+
# pawn.MovementSpeedModifier = 1.0
73+
# print("Disabling noclip")
74+
# pc.bCheatFlying = False
75+
# pawn.CheatWalk()
76+
# pc.Restart(False)
77+
# pawn.AccelRate = 2048
78+
# pawn.AirSpeed = 440
79+
# else:
80+
# print("Enabling noclip")
81+
# pawn.Physics = 0x4
82+
# pawn.PhysicsVolume.FluidFriction = 2.0
83+
# pawn.MovementSpeedModifier = 40
84+
# pawn.CheatFly()
85+
# pc.bCheatFlying = True
86+
# pc.ClientGotoState(bl2sdk.FName("PlayerFlying"), bl2sdk.FName())
87+
# pawn.AccelRate = 20000
88+
# pawn.AirSpeed = 3000
89+
# pawn.CheatGhost()

Python/init.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ def log(s):
55
if not s.endswith('\n'):
66
s += '\n'
77
bl2sdk.Log(s)
8-
print = log
8+
print = log
9+
10+
import commander_wannabe

bl2-sdk/BL2-SDK.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace BL2SDK
3636
tStaticConstructObject pStaticConstructObject;
3737
tLoadPackage pLoadPackage;
3838
tByteOrderSerialize pByteOrderSerialize;
39+
UObject *engine = nullptr;
3940

4041
CPythonInterface *Python;
4142

@@ -406,4 +407,11 @@ namespace BL2SDK
406407
}
407408
SetIsLoadingUDKPackage(false);
408409
};
410+
411+
UObject *GetEngine()
412+
{
413+
if (!engine)
414+
engine = UObject::FindObjectByFullName("WillowGameEngine Transient.WillowGameEngine");
415+
return engine;
416+
}
409417
}

bl2-sdk/BL2-SDK.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ namespace BL2SDK
4040
extern int EngineVersion;
4141
extern int ChangelistNumber;
4242

43+
extern class UObject *engine;
44+
4345
void LogAllProcessEventCalls(bool enabled);
4446
void LogAllUnrealScriptCalls(bool enabled);
4547
//bool getGameVersion(std::wstring& appVersion);
4648
void doInjectedCallNext();
4749
void initialize(wchar_t * exeBaseFolder/*LauncherStruct* args*/);
4850
void cleanup();
4951
void LoadPackage(const char* filename, DWORD flags = 0, bool force = false);
52+
UObject *GetEngine();
5053
}
5154

5255
#endif

bl2-sdk/CPythonInterface.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ PYBIND11_EMBEDDED_MODULE(bl2sdk, m)
7777
m.def("Log", [](std::string in) { Logging::Log(in.c_str(), in.length()); });
7878
m.def("LoadPackage", &BL2SDK::LoadPackage);
7979
m.def("RegisterEngineHook", &RegisterEngineHook);
80+
m.def("GetEngine", &BL2SDK::GetEngine, py::return_value_policy::reference);
8081
m.def("RegisterScriptHook", &RegisterScriptHook);
8182
m.def("RemoveEngineHook", [](const std::string& funcName, const std::string& hookName) {GameHooks::EngineHookManager->Remove(funcName, hookName); });
8283
m.def("RemoveScriptHook", [](const std::string& funcName, const std::string& hookName) {GameHooks::UnrealScriptHookManager->Remove(funcName, hookName); });
@@ -165,6 +166,8 @@ PythonStatus CPythonInterface::InitializeModules()
165166
void CPythonInterface::SetPaths()
166167
{
167168
m_PythonPath = Util::Narrow(Settings::GetPythonFile(L""));
169+
const char *pythonString = Util::Format("import sys;sys.path.append(r'%s\\')", m_PythonPath.c_str()).c_str();
170+
DoString(pythonString);
168171
}
169172

170173
int CPythonInterface::DoFile(const char *filename)

bl2-sdk/TypeMap.h

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ static std::map<std::string, const std::type_info *> uobject_type_map{
434434
{"UDistributionFloatParticleParameter", &typeid(UDistributionFloatParameterBase)},
435435
{"UDistributionVectorParticleParameter", &typeid(UDistributionVectorParameterBase)},
436436
{"UPhysXParticleSystem", &typeid(UPhysXParticleSystem)},
437+
{"UParticleSystem", &typeid(UParticleSystem)},
437438
{"AKActor", &typeid(AKActor)},
438439
{"AKActorFromStatic", &typeid(AKActorFromStatic)},
439440
{"AKActorSpawnable", &typeid(AKActorSpawnable)},

bl2-sdk/gamedefines.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ struct FString : public TArray<wchar_t>
123123

124124
FString(wchar_t* Other)
125125
{
126-
this->Max = this->Count = *Other ? (wcslen(Other) + 1) : 0;
126+
this->Max = this->Count = Other ? (wcslen(Other) + 1) : 0;
127+
this->Data = (wchar_t *)calloc(this->Count, sizeof(wchar_t));
127128

128129
if (this->Count)
129-
this->Data = Other;
130+
wcscpy(this->Data, Other);
130131
};
131132

132133
~FString() {};

bl2-sdk/pydefs/Engine_classes.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -16196,5 +16196,41 @@ void Export_pystes_Engine_classes(py::module &m)
1619616196
.def_static("StaticClass", &AWindDirectionalSource::StaticClass, py::return_value_policy::reference)
1619716197
.def_readwrite("Component", &AWindDirectionalSource::Component)
1619816198
;
16199+
py::class_< UParticleSystem, UObject >(m, "UParticleSystem")
16200+
.def_static("StaticClass", &UParticleSystem::StaticClass, py::return_value_policy::reference)
16201+
.def_readwrite("Emitters", &UParticleSystem::Emitters, py::return_value_policy::reference)
16202+
.def_readwrite("PreviewComponent", &UParticleSystem::PreviewComponent, py::return_value_policy::reference)
16203+
.def_readwrite("CurveEdSetup", &UParticleSystem::CurveEdSetup, py::return_value_policy::reference)
16204+
.def_readwrite("LODDistances", &UParticleSystem::LODDistances, py::return_value_policy::reference)
16205+
.def_readwrite("LODSettings", &UParticleSystem::LODSettings, py::return_value_policy::reference)
16206+
.def_readwrite("PhysxParticleSystemRef", &UParticleSystem::PhysxParticleSystemRef, py::return_value_policy::reference)
16207+
.def_readwrite("CustomOcclusionBounds", &UParticleSystem::CustomOcclusionBounds, py::return_value_policy::reference)
16208+
.def_readwrite("StartAudioEvent", &UParticleSystem::StartAudioEvent, py::return_value_policy::reference)
16209+
.def_readwrite("StopAudioEvent", &UParticleSystem::StopAudioEvent, py::return_value_policy::reference)
16210+
.def_readwrite("StartLoopingAudioEvent", &UParticleSystem::StartLoopingAudioEvent, py::return_value_policy::reference)
16211+
.def_readwrite("StopLoopingAudioEvent", &UParticleSystem::StopLoopingAudioEvent, py::return_value_policy::reference)
16212+
.def_readwrite("MacroUVPosition", &UParticleSystem::MacroUVPosition, py::return_value_policy::reference)
16213+
.def_readwrite("FixedRelativeBoundingBox", &UParticleSystem::FixedRelativeBoundingBox, py::return_value_policy::reference)
16214+
.def_readwrite("SystemUpdateMode", &UParticleSystem::SystemUpdateMode)
16215+
.def_readwrite("LODMethod", &UParticleSystem::LODMethod)
16216+
.def_readwrite("OcclusionBoundsMethod", &UParticleSystem::OcclusionBoundsMethod)
16217+
.def_readwrite("UpdateTime_FPS", &UParticleSystem::UpdateTime_FPS)
16218+
.def_readwrite("UpdateTime_Delta", &UParticleSystem::UpdateTime_Delta)
16219+
.def_readwrite("WarmupTime", &UParticleSystem::WarmupTime)
16220+
.def_readwrite("fAudioDelaySeconds", &UParticleSystem::fAudioDelaySeconds)
16221+
.def_readwrite("LODDistanceCheckTime", &UParticleSystem::LODDistanceCheckTime)
16222+
.def_readwrite("MaxDrawDistance", &UParticleSystem::MaxDrawDistance)
16223+
.def_readwrite("SecondsBeforeInactive", &UParticleSystem::SecondsBeforeInactive)
16224+
.def_readwrite("Delay", &UParticleSystem::Delay)
16225+
.def_readwrite("DelayLow", &UParticleSystem::DelayLow)
16226+
.def_readwrite("MacroUVRadius", &UParticleSystem::MacroUVRadius)
16227+
.def("EffectiveParticleSystemAfterPhysXMutator", &UParticleSystem::EffectiveParticleSystemAfterPhysXMutator, py::return_value_policy::reference)
16228+
.def("GetMaxLifespan", &UParticleSystem::GetMaxLifespan)
16229+
.def("SetLODDistance", &UParticleSystem::SetLODDistance)
16230+
.def("SetCurrentLODMethod", &UParticleSystem::SetCurrentLODMethod)
16231+
.def("GetLODDistance", &UParticleSystem::GetLODDistance)
16232+
.def("GetLODLevelCount", &UParticleSystem::GetLODLevelCount)
16233+
.def("GetCurrentLODMethod", &UParticleSystem::GetCurrentLODMethod)
16234+
;
1619916235

1620016236
}

0 commit comments

Comments
 (0)