Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory issue #65

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions BDTHPlugin/PluginMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class PluginMemory

public unsafe LayoutWorld* Layout => (LayoutWorld*)layoutWorldPtr;
public unsafe HousingStructure* HousingStructure => Layout->HousingStruct;
public unsafe HousingModule* HousingModule => (HousingModule*)housingModulePtr;
public unsafe HousingObjectManger* CurrentManager => HousingModule->GetCurrentManager();
public unsafe HousingModule* HousingModule => housingModulePtr != IntPtr.Zero ? (HousingModule*) Marshal.ReadIntPtr(housingModulePtr) : null;
public unsafe HousingObjectManager* CurrentManager => HousingModule->GetCurrentManager();
public unsafe Camera* Camera => &CameraManager.Instance()->GetActiveCamera()->CameraBase.SceneCamera;

public static unsafe AtkUnitBase* HousingLayout => (AtkUnitBase*)Plugin.GameGui.GetAddonByName("HousingLayout", 1);
Expand Down Expand Up @@ -149,11 +149,10 @@ public PluginMemory()

// Pointers for housing structures.
layoutWorldPtr = Plugin.TargetModuleScanner.GetStaticAddressFromSig("48 8B D1 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 0A", 3);
housingModulePtr = Plugin.TargetModuleScanner.GetStaticAddressFromSig("40 53 48 83 EC ?? 33 ?? 48 39 ?? ?? ?? ?? 01 75", 8);
housingModulePtr = Plugin.TargetModuleScanner.GetStaticAddressFromSig("48 8B 05 ?? ?? ?? ?? 8B 52");

// Read the pointers.
layoutWorldPtr = Marshal.ReadIntPtr(layoutWorldPtr);
housingModulePtr = Marshal.ReadIntPtr(housingModulePtr);

// Select housing item.
selectItemAddress = Plugin.TargetModuleScanner.ScanText("E8 ?? ?? 00 00 48 8B CE E8 ?? ?? 00 00 48 8B ?? ?? ?? 48");
Expand Down
10 changes: 5 additions & 5 deletions BDTHPlugin/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum ItemState2
}

[StructLayout(LayoutKind.Explicit)]
public unsafe struct HousingObjectManger
public unsafe struct HousingObjectManager
{
[FieldOffset(0x8980)] public fixed ulong Objects[400];
[FieldOffset(0x96E8)] public HousingGameObject* IndoorActiveObject2;
Expand All @@ -43,11 +43,11 @@ public unsafe struct HousingObjectManger
[StructLayout(LayoutKind.Explicit)]
public unsafe struct HousingModule
{
[FieldOffset(0x0)] public HousingObjectManger* CurrentTerritory;
[FieldOffset(0x8)] public HousingObjectManger* OutdoorTerritory;
[FieldOffset(0x10)] public HousingObjectManger* IndoorTerritory;
[FieldOffset(0x0)] public HousingObjectManager* CurrentTerritory;
[FieldOffset(0x8)] public HousingObjectManager* OutdoorTerritory;
[FieldOffset(0x10)] public HousingObjectManager* IndoorTerritory;

public HousingObjectManger* GetCurrentManager()
public HousingObjectManager* GetCurrentManager()
=> OutdoorTerritory != null ? OutdoorTerritory : IndoorTerritory;
}

Expand Down
Loading