From 19de23d67bf187ab55a0810662fa2defc9211b9b Mon Sep 17 00:00:00 2001 From: Spitfire_x86 Date: Wed, 4 Mar 2020 23:58:45 +0100 Subject: [PATCH] Add samples --- Ray2Mod.sln | 49 +++++++++++---- Ray2Mod/Ray2Mod.csproj | 2 + samples/HelloWorld/HelloWorld.cs | 38 ++++++++++++ samples/HelloWorld/HelloWorld.csproj | 58 ++++++++++++++++++ samples/HelloWorld/Properties/AssemblyInfo.cs | 36 +++++++++++ samples/HudIcons/HudIcons.cs | 45 ++++++++++++++ samples/HudIcons/HudIcons.csproj | 60 +++++++++++++++++++ samples/HudIcons/Properties/AssemblyInfo.cs | 36 +++++++++++ samples/Pointers/Pointers.cs | 42 +++++++++++++ samples/Pointers/Pointers.csproj | 60 +++++++++++++++++++ samples/Pointers/Properties/AssemblyInfo.cs | 36 +++++++++++ 11 files changed, 450 insertions(+), 12 deletions(-) create mode 100644 samples/HelloWorld/HelloWorld.cs create mode 100644 samples/HelloWorld/HelloWorld.csproj create mode 100644 samples/HelloWorld/Properties/AssemblyInfo.cs create mode 100644 samples/HudIcons/HudIcons.cs create mode 100644 samples/HudIcons/HudIcons.csproj create mode 100644 samples/HudIcons/Properties/AssemblyInfo.cs create mode 100644 samples/Pointers/Pointers.cs create mode 100644 samples/Pointers/Pointers.csproj create mode 100644 samples/Pointers/Properties/AssemblyInfo.cs diff --git a/Ray2Mod.sln b/Ray2Mod.sln index 67a8156..f4588ef 100644 --- a/Ray2Mod.sln +++ b/Ray2Mod.sln @@ -9,6 +9,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModRunner", "ModRunner\ModR EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLoader", "ModLoader\ModLoader.csproj", "{3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{A3995D66-9136-47E7-B180-22E419532C5E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "samples\HelloWorld\HelloWorld.csproj", "{43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HudIcons", "samples\HudIcons\HudIcons.csproj", "{70BB4075-F09B-44B2-B61D-6599A3FC0FD3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pointers", "samples\Pointers\Pointers.csproj", "{1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,34 +25,51 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Debug|Any CPU.ActiveCfg = Debug|x86 {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Debug|x86.ActiveCfg = Debug|x86 {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Debug|x86.Build.0 = Debug|x86 - {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Release|Any CPU.Build.0 = Release|Any CPU + {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Release|Any CPU.ActiveCfg = Release|x86 {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Release|x86.ActiveCfg = Release|x86 {A88B3B19-48B3-4D6B-A217-8AF81926BE25}.Release|x86.Build.0 = Release|x86 - {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Debug|Any CPU.ActiveCfg = Debug|x86 {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Debug|x86.ActiveCfg = Debug|x86 {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Debug|x86.Build.0 = Debug|x86 - {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Release|Any CPU.Build.0 = Release|Any CPU + {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Release|Any CPU.ActiveCfg = Release|x86 {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Release|x86.ActiveCfg = Release|x86 {8466F3F6-880D-46E1-93BC-47E8B5C97195}.Release|x86.Build.0 = Release|x86 - {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Debug|Any CPU.ActiveCfg = Debug|x86 {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Debug|x86.ActiveCfg = Debug|x86 {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Debug|x86.Build.0 = Debug|x86 - {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Release|Any CPU.Build.0 = Release|Any CPU + {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Release|Any CPU.ActiveCfg = Release|x86 {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Release|x86.ActiveCfg = Release|x86 {3F23F2BB-BF9A-4CA9-9A3C-14C1A74FF98A}.Release|x86.Build.0 = Release|x86 + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}.Debug|Any CPU.ActiveCfg = Debug|x86 + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}.Debug|x86.ActiveCfg = Debug|x86 + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}.Debug|x86.Build.0 = Debug|x86 + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}.Release|Any CPU.ActiveCfg = Release|x86 + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}.Release|x86.ActiveCfg = Release|x86 + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}.Release|x86.Build.0 = Release|x86 + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3}.Debug|Any CPU.ActiveCfg = Debug|x86 + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3}.Debug|x86.ActiveCfg = Debug|x86 + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3}.Debug|x86.Build.0 = Debug|x86 + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3}.Release|Any CPU.ActiveCfg = Release|x86 + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3}.Release|x86.ActiveCfg = Release|x86 + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3}.Release|x86.Build.0 = Release|x86 + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}.Debug|Any CPU.ActiveCfg = Debug|x86 + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}.Debug|x86.ActiveCfg = Debug|x86 + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}.Debug|x86.Build.0 = Debug|x86 + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}.Release|Any CPU.ActiveCfg = Release|x86 + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}.Release|x86.ActiveCfg = Release|x86 + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F} = {A3995D66-9136-47E7-B180-22E419532C5E} + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3} = {A3995D66-9136-47E7-B180-22E419532C5E} + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5} = {A3995D66-9136-47E7-B180-22E419532C5E} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6F5E3E32-BBC8-41B0-B0BB-E41DD6097B39} EndGlobalSection diff --git a/Ray2Mod/Ray2Mod.csproj b/Ray2Mod/Ray2Mod.csproj index 40a11c9..66b0d64 100644 --- a/Ray2Mod/Ray2Mod.csproj +++ b/Ray2Mod/Ray2Mod.csproj @@ -23,6 +23,7 @@ prompt MinimumRecommendedRules.ruleset true + ..\bin\Debug\Ray2Mod.xml ..\bin\Release\ @@ -34,6 +35,7 @@ prompt MinimumRecommendedRules.ruleset true + ..\bin\Release\Ray2Mod.xml diff --git a/samples/HelloWorld/HelloWorld.cs b/samples/HelloWorld/HelloWorld.cs new file mode 100644 index 0000000..efed231 --- /dev/null +++ b/samples/HelloWorld/HelloWorld.cs @@ -0,0 +1,38 @@ +using Ray2Mod; +using Ray2Mod.Components; +using Ray2Mod.Game; +using Ray2Mod.Utils; + +namespace HelloWorld +{ + public class HelloWorld : IMod + { + // Instances of HookManager and GameFunctions have to be stored + // as fields or properties to prevent the hooks from unloading. + private HookManager Manager { get; set; } + private GameFunctions Game { get; set; } + + public void Run(RemoteInterface remoteInterface) + { + Manager = new HookManager(); + Game = new GameFunctions(remoteInterface); + + // InitMainLoops creates hooks to 3 functions: VEngine (main engine loop), + // DrawsTexts (text drawing loop), and VirtualKeyToAscii (input reading function). + // The first two are executed on every frame. + // The input function is executed whenever a keyboard input occurs. + Manager.InitMainLoops(Game); + + // By subscribing to the TextFunctions.Actions event, + // the following code will be executed inside the text drawing loop. + // Attempting to draw text outside of that loop will crash the game. + Game.Text.Actions += () => + { + // Draw 2D text overlay on screen. + // The X and Y values are coordinates on the screen space, mapped to a 1000x1000 area. + Game.Text.CustomText("Hello World", 10, 5, 5); + Game.Text.CustomText("This text is red and transparent".Red(), 10, 5, 30, 180); + }; + } + } +} diff --git a/samples/HelloWorld/HelloWorld.csproj b/samples/HelloWorld/HelloWorld.csproj new file mode 100644 index 0000000..9b54883 --- /dev/null +++ b/samples/HelloWorld/HelloWorld.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {43B48BE4-5AAB-474D-AF04-2B794AF2AD8F} + Library + Properties + HelloWorld + HelloWorld + v4.5.2 + 512 + true + + + true + ..\..\bin\Debug\samples\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + ..\..\bin\Release\samples\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + + + + + {a88b3b19-48b3-4d6b-a217-8af81926be25} + Ray2Mod + False + + + + \ No newline at end of file diff --git a/samples/HelloWorld/Properties/AssemblyInfo.cs b/samples/HelloWorld/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..42847b1 --- /dev/null +++ b/samples/HelloWorld/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("HelloWorld")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HelloWorld")] +[assembly: AssemblyCopyright("Copyright © RayTools 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("43b48be4-5aab-474d-af04-2b794af2ad8f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/samples/HudIcons/HudIcons.cs b/samples/HudIcons/HudIcons.cs new file mode 100644 index 0000000..c5113be --- /dev/null +++ b/samples/HudIcons/HudIcons.cs @@ -0,0 +1,45 @@ +using Ray2Mod; +using Ray2Mod.Components; +using Ray2Mod.Components.Types; +using Ray2Mod.Game; +using Ray2Mod.Game.Structs; +using Ray2Mod.Utils; + +namespace HudIcons +{ + public class HudIcons : IMod + { + private HookManager Manager { get; set; } + private GameFunctions Game { get; set; } + + public void Run(RemoteInterface remoteInterface) + { + Manager = new HookManager(); + Game = new GameFunctions(remoteInterface); + Manager.InitMainLoops(Game); + + // All particles, HUD icons and other GFX objects should always be drawn in the main engine loop. + Game.Engine.Actions += () => + { + // Create 2 vectors - upper-left and lower-right corner of the icon. + // For HUD icons, the screen space is mapped to a 100x100 area. + // Only X and Y coordinates are used to position the icon. + // The Z coordinate of the 2nd vector is the alpha/transparency value. + Vector3 vPos1 = new Vector3(5, 5, 0); + Vector3 vPos2 = new Vector3(20, 20, 255); + + // StructPtr copies the vector structure to unmanaged memory and provides a pointer. + // The memory can be freed automatically at the end of the using block or by calling StructPtr.Dispose(). + using (StructPtr pos1 = new StructPtr(vPos1), pos2 = new StructPtr(vPos2)) + { + // Particle type 125 is the HUD icon type. + // The last parameter "a6" varies between particle types - in this case it's an index. + // A specific index value can only be used by one icon. If multiple icons are drawn + // with the same index, only the last one will be displayed. + Game.Gfx.VAddParticle.Call(125, pos1, pos2, TexturePointers.rayIcon, 11); + } + + }; + } + } +} diff --git a/samples/HudIcons/HudIcons.csproj b/samples/HudIcons/HudIcons.csproj new file mode 100644 index 0000000..3d6576d --- /dev/null +++ b/samples/HudIcons/HudIcons.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {70BB4075-F09B-44B2-B61D-6599A3FC0FD3} + Library + Properties + HudIcons + HudIcons + v4.5.2 + 512 + true + + + true + ..\..\bin\Debug\samples\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + MinimumRecommendedRules.ruleset + true + + + ..\..\bin\Release\samples\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + {a88b3b19-48b3-4d6b-a217-8af81926be25} + Ray2Mod + False + + + + \ No newline at end of file diff --git a/samples/HudIcons/Properties/AssemblyInfo.cs b/samples/HudIcons/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a09c9c2 --- /dev/null +++ b/samples/HudIcons/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("HudIcons")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HudIcons")] +[assembly: AssemblyCopyright("Copyright © RayTools 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("70bb4075-f09b-44b2-b61d-6599a3fc0fd3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/samples/Pointers/Pointers.cs b/samples/Pointers/Pointers.cs new file mode 100644 index 0000000..b4b9c23 --- /dev/null +++ b/samples/Pointers/Pointers.cs @@ -0,0 +1,42 @@ +using Ray2Mod; +using Ray2Mod.Components; +using Ray2Mod.Game; +using Ray2Mod.Game.Structs; +using Ray2Mod.Utils; + +namespace Pointers +{ + public unsafe class Pointers : IMod + { + private HookManager Manager; + private GameFunctions Game; + + public void Run(RemoteInterface remoteInterface) + { + Manager = new HookManager(); + Game = new GameFunctions(remoteInterface); + Manager.InitMainLoops(Game); + + // Static addresses can be directly assigned to an unsafe pointer. + byte* engineState = (byte*)0x500380; + + // Pointer/offset paths can be read at runtime using Memory.GetPointerAtOffset. + Vector3* position = (Vector3*)Memory.GetPointerAtOffset(0x500560, 0x224, 0x310, 0x34, 0x0, 0x1ac); + + // Display values as in-game text + Game.Text.Actions += () => + { + // Utils.Text provides many extension methods that simplify in-game text formatting. + // The second line is equivalent to: + // "/O200:X/O0:\\" + (position->X).ToString("0.000", CultureInfo.InvariantCulture) + "/l:" + string coordinates = "Coordinates=".NL() + + "X".KeyValue(position->X.D3()).NL() + + "Y".KeyValue(position->Y.D3()).NL() + + "Z".KeyValue(position->Z.D3()).NL(); + + Game.Text.CustomText(coordinates, 10, 5, 5); + Game.Text.CustomText($"EngineState={*engineState}", 10, 5, 200); + }; + } + } +} diff --git a/samples/Pointers/Pointers.csproj b/samples/Pointers/Pointers.csproj new file mode 100644 index 0000000..bf35912 --- /dev/null +++ b/samples/Pointers/Pointers.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {1C0A9FBF-4DBB-43EB-AF58-E03A2F4BD9A5} + Library + Properties + Pointers + Pointers + v4.5.2 + 512 + true + + + true + ..\..\bin\Debug\samples\ + DEBUG;TRACE + true + full + x86 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + ..\..\bin\Release\samples\ + TRACE + true + true + pdbonly + x86 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + + + + + {a88b3b19-48b3-4d6b-a217-8af81926be25} + Ray2Mod + False + + + + \ No newline at end of file diff --git a/samples/Pointers/Properties/AssemblyInfo.cs b/samples/Pointers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..70236ad --- /dev/null +++ b/samples/Pointers/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Pointers")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Pointers")] +[assembly: AssemblyCopyright("Copyright © RayTools 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1c0a9fbf-4dbb-43eb-af58-e03a2f4bd9a5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]