Skip to content

Commit

Permalink
Add ParticleSystem, fix FString, add GetEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Hurd committed Apr 5, 2019
1 parent e360f55 commit 31000de
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 62 deletions.
59 changes: 0 additions & 59 deletions Python/commander.py

This file was deleted.

89 changes: 89 additions & 0 deletions Python/commander_wannabe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import bl2sdk
import math

class Controller():
CurrentKeys = set()
isThirdPerson = False

def process_input(self, caller, function, parms, result):
ControllerId = parms.popInt()
Key = parms.popFName()
EventType = parms.popByte()
name = Key.GetName()
if EventType == 0:
self.CurrentKeys.add(name)
if 'LeftControl' in self.CurrentKeys or 'RightControl' in self.CurrentKeys:
if name == 'Up':
move_forward_backward(100)
if name == 'Down':
move_forward_backward(-100)
if name == 'Left':
move_left_right(-100)
if name == 'Right':
move_left_right(100)
if 'NumPadNine' == name:
self.toggle_third_person()
elif EventType == 1 and name in self.CurrentKeys:
self.CurrentKeys.remove(name)

def toggle_third_person(self):
engine = bl2sdk.GetEngine()
pc = engine.GamePlayers[0].Actor
new_mode = 'camera ' + ('1st' if self.isThirdPerson else '3rd')
pc.ConsoleCommand(bl2sdk.FString(new_mode), 0)
print(new_mode)
self.isThirdPerson = not self.isThirdPerson

def convert_rotation(rotation):
conversion = 65535.0 / math.pi / 2.0
degree_pitch = rotation.Pitch / conversion
degree_yaw = rotation.Yaw / conversion
return degree_pitch, degree_yaw

def move_forward_backward(distance):
engine = bl2sdk.GetEngine()
pawn = engine.GamePlayers[0].Actor.AcknowledgedPawn
position = pawn.Location
pitch, yaw = convert_rotation(pawn.Rotation)
position.Z += math.sin(pitch) * distance
position.X += math.cos(yaw) * math.cos(pitch) * distance
position.Y += math.sin(yaw) * math.cos(pitch) * distance

def move_left_right(distance):
engine = bl2sdk.GetEngine()
pawn = engine.GamePlayers[0].Actor.AcknowledgedPawn
position = pawn.Location
pitch, yaw = convert_rotation(pawn.Rotation)
position.X += math.cos(yaw + math.pi / 2) * distance
position.Y += math.sin(yaw + math.pi / 2) * distance


bl2sdk.RemoveEngineHook("Function WillowGame.WillowGameViewportClient.InputKey", "DoCommanderThings")
bl2sdk.RegisterEngineHook("Function WillowGame.WillowGameViewportClient.InputKey", "DoCommanderThings", Controller().process_input)


# def noclip():
# pc = engine.GamePlayers[0].Actor
# pawn = pc.AcknowledgedPawn
# pc.WorldInfo.Game.AllowCheats(pc)
# if pc.bCheatFlying:
# pawn.Physics = 0x1
# pawn.PhysicsVolume.FluidFriction = 0.3
# pawn.MovementSpeedModifier = 1.0
# print("Disabling noclip")
# pc.bCheatFlying = False
# pawn.CheatWalk()
# pc.Restart(False)
# pawn.AccelRate = 2048
# pawn.AirSpeed = 440
# else:
# print("Enabling noclip")
# pawn.Physics = 0x4
# pawn.PhysicsVolume.FluidFriction = 2.0
# pawn.MovementSpeedModifier = 40
# pawn.CheatFly()
# pc.bCheatFlying = True
# pc.ClientGotoState(bl2sdk.FName("PlayerFlying"), bl2sdk.FName())
# pawn.AccelRate = 20000
# pawn.AirSpeed = 3000
# pawn.CheatGhost()
4 changes: 3 additions & 1 deletion Python/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ def log(s):
if not s.endswith('\n'):
s += '\n'
bl2sdk.Log(s)
print = log
print = log

import commander_wannabe
8 changes: 8 additions & 0 deletions bl2-sdk/BL2-SDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace BL2SDK
tStaticConstructObject pStaticConstructObject;
tLoadPackage pLoadPackage;
tByteOrderSerialize pByteOrderSerialize;
UObject *engine = nullptr;

CPythonInterface *Python;

Expand Down Expand Up @@ -406,4 +407,11 @@ namespace BL2SDK
}
SetIsLoadingUDKPackage(false);
};

UObject *GetEngine()
{
if (!engine)
engine = UObject::FindObjectByFullName("WillowGameEngine Transient.WillowGameEngine");
return engine;
}
}
3 changes: 3 additions & 0 deletions bl2-sdk/BL2-SDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ namespace BL2SDK
extern int EngineVersion;
extern int ChangelistNumber;

extern class UObject *engine;

void LogAllProcessEventCalls(bool enabled);
void LogAllUnrealScriptCalls(bool enabled);
//bool getGameVersion(std::wstring& appVersion);
void doInjectedCallNext();
void initialize(wchar_t * exeBaseFolder/*LauncherStruct* args*/);
void cleanup();
void LoadPackage(const char* filename, DWORD flags = 0, bool force = false);
UObject *GetEngine();
}

#endif
3 changes: 3 additions & 0 deletions bl2-sdk/CPythonInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ PYBIND11_EMBEDDED_MODULE(bl2sdk, m)
m.def("Log", [](std::string in) { Logging::Log(in.c_str(), in.length()); });
m.def("LoadPackage", &BL2SDK::LoadPackage);
m.def("RegisterEngineHook", &RegisterEngineHook);
m.def("GetEngine", &BL2SDK::GetEngine, py::return_value_policy::reference);
m.def("RegisterScriptHook", &RegisterScriptHook);
m.def("RemoveEngineHook", [](const std::string& funcName, const std::string& hookName) {GameHooks::EngineHookManager->Remove(funcName, hookName); });
m.def("RemoveScriptHook", [](const std::string& funcName, const std::string& hookName) {GameHooks::UnrealScriptHookManager->Remove(funcName, hookName); });
Expand Down Expand Up @@ -165,6 +166,8 @@ PythonStatus CPythonInterface::InitializeModules()
void CPythonInterface::SetPaths()
{
m_PythonPath = Util::Narrow(Settings::GetPythonFile(L""));
const char *pythonString = Util::Format("import sys;sys.path.append(r'%s\\')", m_PythonPath.c_str()).c_str();
DoString(pythonString);
}

int CPythonInterface::DoFile(const char *filename)
Expand Down
1 change: 1 addition & 0 deletions bl2-sdk/TypeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ static std::map<std::string, const std::type_info *> uobject_type_map{
{"UDistributionFloatParticleParameter", &typeid(UDistributionFloatParameterBase)},
{"UDistributionVectorParticleParameter", &typeid(UDistributionVectorParameterBase)},
{"UPhysXParticleSystem", &typeid(UPhysXParticleSystem)},
{"UParticleSystem", &typeid(UParticleSystem)},
{"AKActor", &typeid(AKActor)},
{"AKActorFromStatic", &typeid(AKActorFromStatic)},
{"AKActorSpawnable", &typeid(AKActorSpawnable)},
Expand Down
5 changes: 3 additions & 2 deletions bl2-sdk/gamedefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ struct FString : public TArray<wchar_t>

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

if (this->Count)
this->Data = Other;
wcscpy(this->Data, Other);
};

~FString() {};
Expand Down
36 changes: 36 additions & 0 deletions bl2-sdk/pydefs/Engine_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16196,5 +16196,41 @@ void Export_pystes_Engine_classes(py::module &m)
.def_static("StaticClass", &AWindDirectionalSource::StaticClass, py::return_value_policy::reference)
.def_readwrite("Component", &AWindDirectionalSource::Component)
;
py::class_< UParticleSystem, UObject >(m, "UParticleSystem")
.def_static("StaticClass", &UParticleSystem::StaticClass, py::return_value_policy::reference)
.def_readwrite("Emitters", &UParticleSystem::Emitters, py::return_value_policy::reference)
.def_readwrite("PreviewComponent", &UParticleSystem::PreviewComponent, py::return_value_policy::reference)
.def_readwrite("CurveEdSetup", &UParticleSystem::CurveEdSetup, py::return_value_policy::reference)
.def_readwrite("LODDistances", &UParticleSystem::LODDistances, py::return_value_policy::reference)
.def_readwrite("LODSettings", &UParticleSystem::LODSettings, py::return_value_policy::reference)
.def_readwrite("PhysxParticleSystemRef", &UParticleSystem::PhysxParticleSystemRef, py::return_value_policy::reference)
.def_readwrite("CustomOcclusionBounds", &UParticleSystem::CustomOcclusionBounds, py::return_value_policy::reference)
.def_readwrite("StartAudioEvent", &UParticleSystem::StartAudioEvent, py::return_value_policy::reference)
.def_readwrite("StopAudioEvent", &UParticleSystem::StopAudioEvent, py::return_value_policy::reference)
.def_readwrite("StartLoopingAudioEvent", &UParticleSystem::StartLoopingAudioEvent, py::return_value_policy::reference)
.def_readwrite("StopLoopingAudioEvent", &UParticleSystem::StopLoopingAudioEvent, py::return_value_policy::reference)
.def_readwrite("MacroUVPosition", &UParticleSystem::MacroUVPosition, py::return_value_policy::reference)
.def_readwrite("FixedRelativeBoundingBox", &UParticleSystem::FixedRelativeBoundingBox, py::return_value_policy::reference)
.def_readwrite("SystemUpdateMode", &UParticleSystem::SystemUpdateMode)
.def_readwrite("LODMethod", &UParticleSystem::LODMethod)
.def_readwrite("OcclusionBoundsMethod", &UParticleSystem::OcclusionBoundsMethod)
.def_readwrite("UpdateTime_FPS", &UParticleSystem::UpdateTime_FPS)
.def_readwrite("UpdateTime_Delta", &UParticleSystem::UpdateTime_Delta)
.def_readwrite("WarmupTime", &UParticleSystem::WarmupTime)
.def_readwrite("fAudioDelaySeconds", &UParticleSystem::fAudioDelaySeconds)
.def_readwrite("LODDistanceCheckTime", &UParticleSystem::LODDistanceCheckTime)
.def_readwrite("MaxDrawDistance", &UParticleSystem::MaxDrawDistance)
.def_readwrite("SecondsBeforeInactive", &UParticleSystem::SecondsBeforeInactive)
.def_readwrite("Delay", &UParticleSystem::Delay)
.def_readwrite("DelayLow", &UParticleSystem::DelayLow)
.def_readwrite("MacroUVRadius", &UParticleSystem::MacroUVRadius)
.def("EffectiveParticleSystemAfterPhysXMutator", &UParticleSystem::EffectiveParticleSystemAfterPhysXMutator, py::return_value_policy::reference)
.def("GetMaxLifespan", &UParticleSystem::GetMaxLifespan)
.def("SetLODDistance", &UParticleSystem::SetLODDistance)
.def("SetCurrentLODMethod", &UParticleSystem::SetCurrentLODMethod)
.def("GetLODDistance", &UParticleSystem::GetLODDistance)
.def("GetLODLevelCount", &UParticleSystem::GetLODLevelCount)
.def("GetCurrentLODMethod", &UParticleSystem::GetCurrentLODMethod)
;

}

0 comments on commit 31000de

Please sign in to comment.