Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Restore camera with position
Browse files Browse the repository at this point in the history
Fix body type being overwritten
  • Loading branch information
JKAnderson committed Apr 3, 2018
1 parent 44c00d7 commit dd0602d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DS Gadget/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<value>219</value>
</setting>
<setting name="HotkeyTest2" serializeAs="String">
<value>220</value>
<value>221</value>
</setting>
</DS_Gadget.Properties.Settings>
</userSettings>
Expand Down
3 changes: 2 additions & 1 deletion DS Gadget/DSInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public void WriteBool(int address, bool value)

public void WriteByte(int address, byte value)
{
WriteProcessMemory(address, BitConverter.GetBytes(value));
// Note: do not BitConverter.GetBytes this, stupid
WriteProcessMemory(address, new byte[] { value });
}

public void WriteBytes(int address, byte[] bytes)
Expand Down
19 changes: 19 additions & 0 deletions DS Gadget/DSOffsets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ public enum WorldState
PosStableAngle = 0xB84,
}

public const int ChrFollowCamPtr = 0x137D6DC;
public const int ChrFollowCamPtr2 = 0x3C;
public const int ChrFollowCamPtr3 = 0x60;
public enum ChrFollowCam
{
RotX = 0xE0,
RotY = 0xE4,
RotZ = 0xE8,
PosX = 0x100,
PosY = 0x104,
PosZ = 0x108,
CamRotX = 0x140,
CamRotY = 0x144,
CamRotZ = 0x148,
TargetRotX = 0x150,
TargetRotY = 0x154,
TargetRotZ = 0x158,
}

public const int Unknown1Ptr = 0x137E204;
public enum Unknown1
{
Expand Down
27 changes: 24 additions & 3 deletions DS Gadget/DSProcess.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Binarysharp.Assemblers.Fasm;
using System;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -97,7 +96,7 @@ private void ReplaceBytes(byte[] victim, int value, int index)
}

#region Pointer loading
private int charData1, charMapData, animData, charPosData, charData2, graphicsData, worldState, unknown1, unknown2;
private int charData1, charMapData, animData, charPosData, charData2, graphicsData, worldState, chrFollowCam, unknown1, unknown2;

public void LoadPointers()
{
Expand All @@ -117,6 +116,10 @@ public void LoadPointers()

worldState = dsInterface.ReadInt32(DSOffsets.WorldStatePtr);

pointer = dsInterface.ReadInt32(DSOffsets.ChrFollowCamPtr);
pointer = dsInterface.ReadInt32(pointer + DSOffsets.ChrFollowCamPtr2);
chrFollowCam = dsInterface.ReadInt32(pointer + DSOffsets.ChrFollowCamPtr3);

unknown1 = dsInterface.ReadInt32(DSOffsets.Unknown1Ptr);

unknown2 = dsInterface.ReadInt32(DSOffsets.Unknown2Ptr);
Expand Down Expand Up @@ -268,6 +271,16 @@ public void PosWarp(float x, float y, float z, float angle)
dsInterface.WriteBool(charMapData + (int)DSOffsets.CharMapData.Warp, true);
}

public byte[] DumpFollowCam()
{
return dsInterface.ReadBytes(chrFollowCam, 512);
}

public void UndumpFollowCam(byte[] bytes)
{
dsInterface.WriteBytes(chrFollowCam, bytes);
}

public void SetGravity(bool enable)
{
dsInterface.WriteFlag32(charData1 + (int)DSOffsets.CharData1.CharFlags1, (uint)DSOffsets.CharFlags1.SetDisableGravity, !enable);
Expand Down Expand Up @@ -655,6 +668,14 @@ public void ResetAnim()
{
dsInterface.WriteInt32(charData1 + (int)DSOffsets.CharData1.ForcePlayAnimation1, 0);
}

public void HotkeyTest1()
{
}

public void HotkeyTest2()
{
}
#endregion
}
}
17 changes: 14 additions & 3 deletions DS Gadget/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private void linkLabelNewVersion_LinkClicked(object sender, LinkLabelLinkClicked
#region Player Tab
private int skipBonfire = 0;
private int storedHP = -1;
private byte[] camDump = null;

private void initPlayer()
{
Expand Down Expand Up @@ -296,6 +297,7 @@ private void posStore()
numericUpDownPosStoredZ.Value = numericUpDownPosZ.Value;
numericUpDownPosStoredAngle.Value = numericUpDownPosAngle.Value;
storedHP = (int)numericUpDownHP.Value;
camDump = dsProcess.DumpFollowCam();
}

private void buttonPosRestore_Click(object sender, EventArgs e)
Expand All @@ -312,6 +314,10 @@ private void posRestore()
dsProcess?.PosWarp(x, y, z, angle);
if (checkBoxStoreHP.Checked && storedHP > 0)
numericUpDownHP.Value = storedHP;
// Two frames for safety, restore camera after warp takes effect
System.Threading.Thread.Sleep(1000 / 15);
if (camDump != null)
dsProcess.UndumpFollowCam(camDump);
}

private void checkBoxGravity_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -409,7 +415,6 @@ private void recalculateStats()
private void comboBoxClass_SelectedIndexChanged(object sender, EventArgs e)
{
DSClass charClass = comboBoxClass.SelectedItem as DSClass;
dsProcess.SetClass(charClass.ID);
numericUpDownVit.Minimum = charClass.Vitality;
numericUpDownAtt.Minimum = charClass.Attunement;
numericUpDownEnd.Minimum = charClass.Endurance;
Expand All @@ -419,7 +424,10 @@ private void comboBoxClass_SelectedIndexChanged(object sender, EventArgs e)
numericUpDownInt.Minimum = charClass.Intelligence;
numericUpDownFth.Minimum = charClass.Faith;
if (!reading)
{
dsProcess.SetClass(charClass.ID);
recalculateStats();
}
}

private void numericUpDownStats_ValueChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -993,11 +1001,14 @@ private void initHotkeys()
#if DEBUG
hotkeys.Add(new GadgetHotkey("HotkeyTest1", textBoxHotkeyTest1, tabPageHotkeys, () =>
{

posStore();
dsProcess.HotkeyTest1();
}));
hotkeys.Add(new GadgetHotkey("HotkeyTest2", textBoxHotkeyTest2, tabPageHotkeys, () =>
{

posRestore();
//System.Threading.Thread.Sleep(1000 / 15);
dsProcess.HotkeyTest2();
}));
#else
textBoxHotkeyTest1.Visible = false;
Expand Down
2 changes: 1 addition & 1 deletion DS Gadget/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DS Gadget/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<Value Profile="(Default)">219</Value>
</Setting>
<Setting Name="HotkeyTest2" Type="System.Int32" Scope="User">
<Value Profile="(Default)">220</Value>
<Value Profile="(Default)">221</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit dd0602d

Please sign in to comment.