Skip to content
Open
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
6 changes: 3 additions & 3 deletions API/DimItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public override bool UseItem(Player player)
}
if (!File.Exists(Main.SavePath + "/World/" + (dimensionName + "/" + Main.worldName + ".wld").Replace(' ', '_')))
{
<<<<<<< HEAD
/**///<<<<<<< HEAD

info.SetValue(Main.ActiveWorldFileData, Main.SavePath + "/World/" + dimensionName + "/" + Main.worldName + ".wld");
startGen();
=======
/*///=======
info.SetValue(Main.ActiveWorldFileData, Main.SavePath + "/World/" + (dimensionName + "/" + Main.worldName + ".wld").Replace(' ', '_'));
generateDimension();
>>>>>>> e6af22ba0365756f77f48c73c0c78257d723705b
/**///>>>>>>> e6af22ba0365756f77f48c73c0c78257d723705b
p.player.Spawn();
WorldFile.saveWorld(false, true);
return true;
Expand Down
75 changes: 6 additions & 69 deletions API/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,6 @@ namespace Dimlibs.API
{
class ReflectionUtil
{
public static MethodInfo OriginalLoadWorld;

public static void MethodSwap(Type OriginalMethodType, String OriginalMethodName, Type NewMethodType, String NewMethodName)
{
if (IntPtr.Size == 4)
{
MethodSwap32Bit(OriginalMethodType, OriginalMethodName, NewMethodType, NewMethodName);
return;
}
MethodSwap64bit(OriginalMethodType, OriginalMethodName, NewMethodType, NewMethodName);
}

public static void OverloadedMethodSwap(Type OriginalMethodType, String OriginalMethodName, Type NewMethodType, String NewMethodName, Type[] parameter = null)
{
if (IntPtr.Size == 4)
{
MethodSwap32Bit(OriginalMethodType, OriginalMethodName, NewMethodType, NewMethodName, parameter);
return;
}
MethodSwap64bit(OriginalMethodType, OriginalMethodName, NewMethodType, NewMethodName, parameter);
}


public static void MethodSwap32Bit(Type OriginalMethodType, String OriginalMethodName, Type NewMethodType, String NewMethodName, Type[] parameter = null)
{
MethodInfo OriginalMethod = (parameter != null)
? OriginalMethodType.GetMethod(OriginalMethodName, parameter)
: OriginalMethodType.GetMethod(OriginalMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);


MethodInfo NewMethod =
NewMethodType.GetMethod(NewMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);

RuntimeHelpers.PrepareMethod(OriginalMethod.MethodHandle);
RuntimeHelpers.PrepareMethod(NewMethod.MethodHandle);

IntPtr ptr = OriginalMethod.MethodHandle.Value + IntPtr.Size * 2;
IntPtr ptr2 = NewMethod.MethodHandle.Value + IntPtr.Size * 2;
int value;

value = ptr.ToInt32();
Marshal.WriteInt32(ptr, Marshal.ReadInt32(ptr2));
Marshal.WriteInt32(ptr2, Marshal.ReadInt32(new IntPtr(value)));

}

public static unsafe void MethodSwap64bit(Type OriginalMethodType, String OriginalMethodName, Type NewMethodType, String NewMethodName, Type[] parameter = null)
{
MethodInfo OriginalMethod = (parameter != null)
? OriginalMethodType.GetMethod(OriginalMethodName, parameter)
: OriginalMethodType.GetMethod(OriginalMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo NewMethod =
NewMethodType.GetMethod(NewMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
RuntimeHelpers.PrepareMethod(OriginalMethod.MethodHandle);
RuntimeHelpers.PrepareMethod(NewMethod.MethodHandle);

long* inj = (long*)NewMethod.MethodHandle.Value.ToPointer() + 1;
long* tar = (long*)OriginalMethod.MethodHandle.Value.ToPointer() + 1;
*tar = *inj;
}

public static Delegate GetEventDelegate(Object obj, string evt)
{
Delegate del = null;
Expand Down Expand Up @@ -111,16 +50,14 @@ public static Object Clone(Object objToClone)

public static void MassSwap()
{
OriginalLoadWorld = typeof(ReflectionUtil).GetMethod("LoadWorld",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
OverloadedMethodSwap(typeof(WorldFile), "saveWorld", typeof(ReflectionUtil), "SaveWorld", new Type[] {typeof(bool), typeof(bool)});
MethodSwap(typeof(WorldFile), "loadWorld", typeof(ReflectionUtil), "LoadWorld");
MethodSwap(typeof(WorldFile), "SaveWorldTiles", typeof(ReflectionUtil), "SaveWorldTiles");
On.Terraria.IO.WorldFile.saveWorld_1 += SaveWorld;
On.Terraria.IO.WorldFile.loadWorld += LoadWorld;
On.Terraria.IO.WorldFile.SaveWorldTiles += SaveWorldTiles;
}



private static int SaveWorldTiles(BinaryWriter writer)
private static int SaveWorldTiles(On.Terraria.IO.WorldFile.orig_SaveWorldTiles orig, BinaryWriter writer)
{
byte[] array = new byte[13];
for (int i = 0; i < Main.maxTilesX; i++)
Expand Down Expand Up @@ -310,7 +247,7 @@ private static int SaveWorldTiles(BinaryWriter writer)
return (int)writer.BaseStream.Position;
}

public static void SaveWorld(bool useCloudSaving, bool resetTime = false)
public static void SaveWorld(On.Terraria.IO.WorldFile.orig_saveWorld_1 orig, bool useCloudSaving, bool resetTime = false)
{
FieldInfo padLockInfo = typeof(WorldFile).GetField("padlock", BindingFlags.Static | BindingFlags.NonPublic);
Object padlock = padLockInfo.GetValue(null);
Expand Down Expand Up @@ -427,7 +364,7 @@ public static void SaveWorld(bool useCloudSaving, bool resetTime = false)
Main.serverGenLock = false;*/
}

public static void LoadWorld(bool loadFromCloud)
public static void LoadWorld(On.Terraria.IO.WorldFile.orig_loadWorld orig, bool loadFromCloud)
{
foreach (DimensionHandler dim in DimWorld.dimensionInstanceHandlers.Values)
{
Expand Down
3 changes: 1 addition & 2 deletions Dimlibs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Reflection;
using Dimlibs.API;
using ReLogic.Utilities;
using Terraria;
using Terraria.Localization;
using Terraria.ModLoader;
Expand All @@ -30,7 +29,7 @@ public override void Load()

public override void Unload()
{
ReflectionUtil.MassSwap();
// TerrariaHooks undoes our swaps for us.
}

public override void PostSetupContent()
Expand Down
13 changes: 7 additions & 6 deletions Dimlibs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_32\Microsoft.Xna.Framework.Xact\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Xact.dll</HintPath>
</Reference>
<Reference Include="ReLogic, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Terraria Full source\ReLogic.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Terraria, Version=1.3.5.1, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\TerrariaUltraApocalypse\bin\Debug\Terraria.exe</HintPath>
<HintPath Condition="Exists('..\TerrariaUltraApocalypse\bin\Debug\Terraria.exe')">..\TerrariaUltraApocalypse\bin\Debug\Terraria.exe</HintPath>
<HintPath Condition="Exists('D:\Program Files (x86)\Steam\steamapps\common\Terraria\Terraria.exe')">D:\Program Files (x86)\Steam\steamapps\common\Terraria\Terraria.exe</HintPath>
</Reference>
<Reference Include="TerrariaHooks">
<HintPath>lib\TerrariaHooks.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>"D:\steam game\steamapps\steamapps\common\Terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
<PostBuildEvent Condition="Exists('D:\steam game\steamapps\steamapps\common\Terraria\tModLoaderServer.exe')">"D:\steam game\steamapps\steamapps\common\Terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
<PostBuildEvent Condition="Exists('D:\Program Files (x86)\Steam\steamapps\common\Terraria\tModLoaderServer.exe')">"D:\Program Files (x86)\Steam\steamapps\common\Terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ version = 0.1.1
displayName = DimLibs
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*
includePDB = true
languageVersion = 6
languageVersion = 6
modReferences = TerrariaHooks
Binary file added lib/TerrariaHooks.dll
Binary file not shown.