Skip to content

Commit

Permalink
Add samples
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfirex86 committed Mar 4, 2020
1 parent 7b30e54 commit 19de23d
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 12 deletions.
49 changes: 37 additions & 12 deletions Ray2Mod.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Ray2Mod/Ray2Mod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>..\bin\Debug\Ray2Mod.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\bin\Release\</OutputPath>
Expand All @@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>..\bin\Release\Ray2Mod.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="EasyHook, Version=2.7.7097.0, Culture=neutral, PublicKeyToken=4b580fca19d0b0c5, processorArchitecture=MSIL">
Expand Down
38 changes: 38 additions & 0 deletions samples/HelloWorld/HelloWorld.cs
Original file line number Diff line number Diff line change
@@ -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);
};
}
}
}
58 changes: 58 additions & 0 deletions samples/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{43B48BE4-5AAB-474D-AF04-2B794AF2AD8F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HelloWorld</RootNamespace>
<AssemblyName>HelloWorld</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\bin\Debug\samples\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\bin\Release\samples\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HelloWorld.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Ray2Mod\Ray2Mod.csproj">
<Project>{a88b3b19-48b3-4d6b-a217-8af81926be25}</Project>
<Name>Ray2Mod</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions samples/HelloWorld/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
45 changes: 45 additions & 0 deletions samples/HudIcons/HudIcons.cs
Original file line number Diff line number Diff line change
@@ -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);
}

};
}
}
}
60 changes: 60 additions & 0 deletions samples/HudIcons/HudIcons.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{70BB4075-F09B-44B2-B61D-6599A3FC0FD3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HudIcons</RootNamespace>
<AssemblyName>HudIcons</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\bin\Debug\samples\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\bin\Release\samples\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HudIcons.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Ray2Mod\Ray2Mod.csproj">
<Project>{a88b3b19-48b3-4d6b-a217-8af81926be25}</Project>
<Name>Ray2Mod</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions samples/HudIcons/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Loading

0 comments on commit 19de23d

Please sign in to comment.