Initial CEF and DirectX overlay implementation (PoC, unfinished)
Still pretty unstable, game might crash at times. Revamp build system and other small fixes
This commit is contained in:
7
Tools/CefTest/App.config
Normal file
7
Tools/CefTest/App.config
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
</configuration>
|
71
Tools/CefTest/CefTest.csproj
Normal file
71
Tools/CefTest/CefTest.csproj
Normal file
@ -0,0 +1,71 @@
|
||||
<?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>{874944F4-2D01-4423-B55C-C651CCBA6630}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>CefTest</RootNamespace>
|
||||
<AssemblyName>CefTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BitmapUtil">
|
||||
<HintPath>..\libs\BitmapUtil.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Drawing.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Remoting" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<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="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Client\CefHost\RageCoop.Client.CefHost.csproj">
|
||||
<Project>{ba750e08-5e41-4b56-8ad5-875716d2ccea}</Project>
|
||||
<Name>RageCoop.Client.CefHost</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
104
Tools/CefTest/Program.cs
Normal file
104
Tools/CefTest/Program.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using RageCoop.Client.CefHost;
|
||||
|
||||
namespace CefTest
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
[SecurityPermission(SecurityAction.Demand)]
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
CefController.Initialize();
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
var controller = CefController.Create(0, new Size(800, 600), out var adapter, BufferMode.Dirty);
|
||||
Application.Run(new Test(adapter, controller));
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
var controller2 = CefController.Create(1, new Size(800, 600), out var adapter2, BufferMode.Full);
|
||||
Application.Run(new Test2(adapter2, controller2));
|
||||
}
|
||||
}
|
||||
|
||||
internal class Test2 : Test
|
||||
{
|
||||
public Test2(CefAdapter adapter, CefController controller) : base(adapter, controller)
|
||||
{
|
||||
Text = "test2: full update";
|
||||
}
|
||||
|
||||
protected override void CefPaint(int bufferSize, Rectangle dirtyRect)
|
||||
{
|
||||
lock (_adapter)
|
||||
{
|
||||
var size = _adapter.Size;
|
||||
var draw = new Bitmap(size.Width, size.Height, size.Width * 4, PixelFormat.Format32bppArgb,
|
||||
_adapter.PtrBuffer);
|
||||
_graphics.DrawImage(draw, Point.Empty);
|
||||
draw.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class Test : Form
|
||||
{
|
||||
protected readonly CefAdapter _adapter;
|
||||
protected readonly CefController _controller;
|
||||
protected readonly Graphics _graphics;
|
||||
|
||||
public Test(CefAdapter adapter, CefController controller)
|
||||
{
|
||||
Text = "test1: partial update";
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
Application.EnableVisualStyles();
|
||||
Size = adapter.Size;
|
||||
_adapter = adapter;
|
||||
_controller = controller;
|
||||
_adapter.OnPaint += CefPaint;
|
||||
controller.LoadUrl("https://www.youtube.com/watch?v=w3rQ3328Tok");
|
||||
KeyDown += TestForm_KeyDown;
|
||||
MouseClick += TestForm_MouseClick;
|
||||
BackColor = Color.AliceBlue;
|
||||
_graphics = CreateGraphics();
|
||||
}
|
||||
|
||||
private void TestForm_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
_controller?.SendMouseClick(e.X, e.Y, 0, GetFrom(e.Button), false, 1);
|
||||
_controller?.SendMouseClick(e.X, e.Y, 0, GetFrom(e.Button), true, 1);
|
||||
}
|
||||
|
||||
public static MouseButton GetFrom(MouseButtons b)
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
case MouseButtons.Left: return MouseButton.Left;
|
||||
case MouseButtons.Middle: return MouseButton.Middle;
|
||||
case MouseButtons.Right: return MouseButton.Right;
|
||||
default:
|
||||
return MouseButton.Left;
|
||||
}
|
||||
}
|
||||
|
||||
private void TestForm_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.R) _controller.LoadUrl("https://www.youtube.com/watch?v=x53lfkuP044/");
|
||||
}
|
||||
|
||||
protected virtual void CefPaint(int bufferSize, Rectangle dirtyRect)
|
||||
{
|
||||
lock (_adapter)
|
||||
{
|
||||
var draw = new Bitmap(dirtyRect.Width, dirtyRect.Height, dirtyRect.Width * 4,
|
||||
PixelFormat.Format32bppArgb, _adapter.PtrBuffer);
|
||||
_graphics.DrawImage(draw, dirtyRect.Location);
|
||||
draw.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
Tools/CefTest/Properties/AssemblyInfo.cs
Normal file
35
Tools/CefTest/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
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("CefTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CefTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[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("874944f4-2d01-4423-b55c-c651ccba6630")]
|
||||
|
||||
// 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")]
|
5
Tools/CefTest/packages.config
Normal file
5
Tools/CefTest/packages.config
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net48" />
|
||||
</packages>
|
17
Tools/DataDumper/DataDumper.csproj
Normal file
17
Tools/DataDumper/DataDumper.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Core\RageCoop.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
145
Tools/DataDumper/Program.cs
Normal file
145
Tools/DataDumper/Program.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using RageCoop.Core;
|
||||
using Formatting = Newtonsoft.Json.Formatting;
|
||||
|
||||
namespace DataDumper;
|
||||
|
||||
internal class WeaponInfo
|
||||
{
|
||||
public string Audio;
|
||||
public float Damage;
|
||||
public string DamageType;
|
||||
public string FireType;
|
||||
public bool IsVehicleWeapon;
|
||||
public string Name;
|
||||
public float Speed;
|
||||
|
||||
public WeaponInfo(XmlNode node)
|
||||
{
|
||||
if (node.Attributes["type"].Value != "CWeaponInfo") throw new Exception("Not a CWeaponInfo node");
|
||||
foreach (XmlNode info in node.ChildNodes)
|
||||
switch (info.Name)
|
||||
{
|
||||
case "Name":
|
||||
Name = info.InnerText;
|
||||
break;
|
||||
case "Audio":
|
||||
Audio = info.InnerText;
|
||||
break;
|
||||
case "FireType":
|
||||
FireType = info.InnerText;
|
||||
break;
|
||||
case "DamageType":
|
||||
DamageType = info.InnerText;
|
||||
break;
|
||||
case "Damage":
|
||||
Damage = info.GetFloat();
|
||||
break;
|
||||
case "Speed":
|
||||
Speed = info.GetFloat();
|
||||
break;
|
||||
}
|
||||
|
||||
IsVehicleWeapon = Name.StartsWith("VEHICLE_WEAPON");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static float GetFloat(this XmlNode n)
|
||||
{
|
||||
return float.Parse(n.Attributes["value"].Value);
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
Dictionary<uint, WeaponInfo> weapons = new();
|
||||
foreach (var f in Directory.GetFiles("meta", "*.meta")) Parse(f, weapons);
|
||||
Directory.CreateDirectory("Weapons");
|
||||
File.WriteAllText("Weapons\\Weapons.json", JsonConvert.SerializeObject(weapons, Formatting.Indented));
|
||||
DumpWeaponHash(weapons, true);
|
||||
}
|
||||
|
||||
private static void Parse(string filename, Dictionary<uint, WeaponInfo> weap)
|
||||
{
|
||||
Console.WriteLine("Parsing " + filename);
|
||||
var doc = new XmlDocument();
|
||||
try
|
||||
{
|
||||
doc.Load(filename);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
var nodes = doc.ChildNodes.ToList();
|
||||
if (nodes.Any(x => x.Name == "CWeaponInfoBlob"))
|
||||
{
|
||||
var infosNode = doc.GetElementsByTagName("Item");
|
||||
foreach (XmlNode n in infosNode)
|
||||
if (n.Attributes["type"]?.Value == "CWeaponInfo")
|
||||
{
|
||||
var info = new WeaponInfo(n);
|
||||
if (!info.Name.StartsWith("VEHICLE_WEAPON") && !info.Name.StartsWith("WEAPON")) continue;
|
||||
var hash = Hash(info.Name);
|
||||
if (weap.ContainsKey(hash))
|
||||
weap[hash] = info;
|
||||
else
|
||||
weap.Add(hash, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DumpWeaponHash(Dictionary<uint, WeaponInfo> weapons, bool sort = false,
|
||||
string path = @"Weapons\WeaponHash.cs")
|
||||
{
|
||||
StringBuilder output = new();
|
||||
List<string> lines = new();
|
||||
var weps = weapons.Where(x => x.Value.Name.StartsWith("WEAPON"));
|
||||
var vehWeaps = weapons.Where(x => x.Value.Name.StartsWith("VEHICLE_WEAPON"));
|
||||
output.Append("public enum WeaponHash : uint\r\n{");
|
||||
foreach (var info in weps)
|
||||
lines.Add($"{CoreUtils.FormatToSharpStyle(info.Value.Name, 7)} = {info.Key.ToHex()}");
|
||||
if (sort) lines.Sort();
|
||||
foreach (var l in lines) output.Append($"\r\n\t{l},");
|
||||
output.AppendLine("\r\n}");
|
||||
output.AppendLine();
|
||||
output.Append("public enum VehicleWeaponHash : uint\r\n{\r\n\tInvalid = 0xFFFFFFFF,");
|
||||
lines = new List<string>();
|
||||
foreach (var info in vehWeaps)
|
||||
lines.Add($"{CoreUtils.FormatToSharpStyle(info.Value.Name)} = {info.Key.ToHex()}");
|
||||
if (sort) lines.Sort();
|
||||
foreach (var l in lines) output.Append($"\r\n\t{l},");
|
||||
output.Append("\r\n}");
|
||||
File.WriteAllText(path, output.ToString());
|
||||
}
|
||||
|
||||
private static List<XmlNode> ToList(this XmlNodeList l)
|
||||
{
|
||||
var nodes = new List<XmlNode>();
|
||||
foreach (XmlNode n in l) nodes.Add(n);
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private static uint Hash(string key)
|
||||
{
|
||||
key = key.ToLower();
|
||||
var i = 0;
|
||||
uint hash = 0;
|
||||
while (i != key.Length)
|
||||
{
|
||||
hash += key[i++];
|
||||
hash += hash << 10;
|
||||
hash ^= hash >> 6;
|
||||
}
|
||||
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 11;
|
||||
hash += hash << 15;
|
||||
return hash;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user