Skip to content

Commit 4f0c9cd

Browse files
author
Sui
committed
Initial
And probably last. Unless, I decide to write an autosplitter.
1 parent 9d53039 commit 4f0c9cd

10 files changed

+462
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ $RECYCLE.BIN/
4141
Network Trash Folder
4242
Temporary Items
4343
.apdisk
44+
45+
*.sublime-workspace
46+
obj/
47+
bin/
48+
*.suo
49+
*.user
50+
*.vspx
51+
*.psess
52+
*.rar

AVP2010Component.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Windows.Forms;
2+
using System.Xml;
3+
using LiveSplit.Model;
4+
using LiveSplit.UI;
5+
using LiveSplit.UI.Components;
6+
7+
namespace LiveSplit.AVP2010
8+
{
9+
class TwoWorldsComponent : LogicComponent
10+
{
11+
private GameMemory _gameMemory;
12+
private LiveSplitState _state;
13+
14+
public TwoWorldsComponent(LiveSplitState state)
15+
{
16+
_state = state;
17+
18+
_gameMemory = new GameMemory();
19+
_gameMemory.OnLoadingChanged += gameMemory_OnLoadingChanged;
20+
_gameMemory.StartReading();
21+
}
22+
23+
public override void Dispose()
24+
{
25+
if (_gameMemory != null)
26+
_gameMemory.Stop();
27+
}
28+
29+
void gameMemory_OnLoadingChanged(object sender, LoadingChangedEventArgs e)
30+
{
31+
_state.IsGameTimePaused = e.IsLoading;
32+
}
33+
34+
public override Control GetSettingsControl(LayoutMode mode)
35+
{
36+
return null;
37+
}
38+
39+
public override void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
40+
{
41+
42+
}
43+
44+
public override string ComponentName
45+
{
46+
get { return "AVP2010"; }
47+
}
48+
49+
public override void SetSettings(XmlNode settings)
50+
{
51+
52+
}
53+
54+
public override XmlNode GetSettings(XmlDocument document)
55+
{
56+
return document.CreateElement("Settings");
57+
}
58+
}
59+
}

AVP2010Factory.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Reflection;
2+
using LiveSplit.AVP2010;
3+
using LiveSplit.UI.Components;
4+
using System;
5+
using LiveSplit.Model;
6+
7+
[assembly: ComponentFactory(typeof(TwoWorldsFactory))]
8+
9+
namespace LiveSplit.AVP2010
10+
{
11+
public class TwoWorldsFactory : IComponentFactory
12+
{
13+
public string ComponentName
14+
{
15+
get { return "AVP2010"; }
16+
}
17+
18+
public string Description
19+
{
20+
get { return "Load time remover for Aliens vs. Predator (2010)"; }
21+
}
22+
23+
public ComponentCategory Category
24+
{
25+
get { return ComponentCategory.Control; }
26+
}
27+
28+
public IComponent Create(LiveSplitState state)
29+
{
30+
return new TwoWorldsComponent(state);
31+
}
32+
33+
public string UpdateName
34+
{
35+
get { return this.ComponentName; }
36+
}
37+
38+
public string UpdateURL
39+
{
40+
get { return ""; }
41+
}
42+
43+
public Version Version
44+
{
45+
get { return Assembly.GetExecutingAssembly().GetName().Version; }
46+
}
47+
48+
public string XMLURL
49+
{
50+
get { return this.UpdateURL + ""; }
51+
}
52+
}
53+
}

GameMemory.cs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using System.Windows.Forms;
7+
8+
namespace LiveSplit.AVP2010
9+
{
10+
class GameMemory
11+
{
12+
public event EventHandler<LoadingChangedEventArgs> OnLoadingChanged;
13+
14+
private Task _thread;
15+
private SynchronizationContext _uiThread;
16+
private CancellationTokenSource _cancelSource;
17+
18+
public void StartReading()
19+
{
20+
if (_thread != null && _thread.Status == TaskStatus.Running)
21+
throw new InvalidOperationException();
22+
if (!(SynchronizationContext.Current is WindowsFormsSynchronizationContext))
23+
throw new InvalidOperationException("SynchronizationContext.Current is not a UI thread.");
24+
25+
_cancelSource = new CancellationTokenSource();
26+
_uiThread = SynchronizationContext.Current;
27+
_thread = Task.Factory.StartNew(() => MemoryReadThread(_cancelSource));
28+
}
29+
30+
public void Stop()
31+
{
32+
if (_cancelSource == null || _thread == null || _thread.Status != TaskStatus.Running)
33+
return;
34+
35+
_cancelSource.Cancel();
36+
_thread.Wait();
37+
}
38+
39+
void MemoryReadThread(CancellationTokenSource cts)
40+
{
41+
while (true)
42+
{
43+
try
44+
{
45+
Process game;
46+
while (!this.TryGetGameProcess(out game))
47+
{
48+
Thread.Sleep(500);
49+
50+
if (cts.IsCancellationRequested)
51+
goto ret;
52+
}
53+
54+
this.HandleProcess(game, cts);
55+
56+
if (cts.IsCancellationRequested)
57+
goto ret;
58+
}
59+
catch (Exception ex) // probably a Win32Exception on access denied to a process
60+
{
61+
Trace.WriteLine(ex.ToString());
62+
Thread.Sleep(1000);
63+
}
64+
}
65+
66+
ret: ;
67+
}
68+
69+
bool TryGetGameProcess(out Process p)
70+
{
71+
p = Process.GetProcesses().FirstOrDefault(x => x.ProcessName.ToLower() == "avp_dx11");
72+
if (p == null || p.HasExited)
73+
return false;
74+
75+
return true;
76+
}
77+
78+
void HandleProcess(Process game, CancellationTokenSource cts)
79+
{
80+
bool prevIsLoading = false;
81+
82+
while (!game.HasExited && !cts.IsCancellationRequested)
83+
{
84+
bool isLoading;
85+
game.ReadBool(game.MainModule.BaseAddress + 0x5DB770, out isLoading);
86+
87+
if (isLoading != prevIsLoading)
88+
{
89+
_uiThread.Post(d => {
90+
if (this.OnLoadingChanged != null)
91+
this.OnLoadingChanged(this, new LoadingChangedEventArgs(isLoading));
92+
}, null);
93+
}
94+
95+
prevIsLoading = isLoading;
96+
97+
Thread.Sleep(15);
98+
}
99+
}
100+
}
101+
102+
class LoadingChangedEventArgs : EventArgs
103+
{
104+
public bool IsLoading { get; private set; }
105+
106+
public LoadingChangedEventArgs(bool isLoading)
107+
{
108+
this.IsLoading = isLoading;
109+
}
110+
}
111+
}

LiveSplit.AVP2010.csproj

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{0BC50821-B4E3-4542-A502-BA24DC8787F5}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>LiveSplit.AVP2010</RootNamespace>
11+
<AssemblyName>LiveSplit.AVP2010</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="LiveSplit.Core">
34+
<HintPath>C:\Files\Apps\Gaming\LiveSplit 1.4\LiveSplit.Core.dll</HintPath>
35+
<Private>False</Private>
36+
</Reference>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Windows.Forms" />
40+
<Reference Include="System.XML" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="UpdateManager">
43+
<HintPath>C:\Files\Apps\Gaming\LiveSplit 1.4\UpdateManager.dll</HintPath>
44+
<Private>False</Private>
45+
</Reference>
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="AVP2010Component.cs" />
49+
<Compile Include="AVP2010Factory.cs" />
50+
<Compile Include="GameMemory.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
<Compile Include="SafeNativeMethods.cs" />
53+
<Compile Include="Util.cs" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<None Include="README.md" />
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
60+
Other similar extension points exist, see Microsoft.Common.targets.
61+
<Target Name="BeforeBuild">
62+
</Target>
63+
<Target Name="AfterBuild">
64+
</Target>
65+
-->
66+
</Project>

LiveSplit.AVP2010.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Express 2013 for Windows Desktop
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveSplit.AVP2010", "LiveSplit.AVP2010.csproj", "{0BC50821-B4E3-4542-A502-BA24DC8787F5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{0BC50821-B4E3-4542-A502-BA24DC8787F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0BC50821-B4E3-4542-A502-BA24DC8787F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0BC50821-B4E3-4542-A502-BA24DC8787F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0BC50821-B4E3-4542-A502-BA24DC8787F5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Properties/AssemblyInfo.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
// General Information about an assembly is controlled through the following
4+
// set of attributes. Change these attribute values to modify the information
5+
// associated with an assembly.
6+
using LiveSplit.AVP2010;
7+
using LiveSplit.UI.Components;
8+
9+
[assembly: AssemblyTitle("LiveSplit.AVP2010")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("SuicideMachine")]
13+
[assembly: AssemblyProduct("LiveSplit.AVP2010")]
14+
[assembly: AssemblyCopyright("")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
18+
// Setting ComVisible to false makes the types in this assembly not visible
19+
// to COM components. If you need to access a type in this assembly from
20+
// COM, set the ComVisible attribute to true on that type.
21+
[assembly: ComVisible(false)]
22+
23+
// The following GUID is for the ID of the typelib if this project is exposed to COM
24+
[assembly: Guid("e77cef10-780e-4ec7-afab-05b9f543b2ef")]
25+
26+
// Version information for an assembly consists of the following four values:
27+
//
28+
// Major Version
29+
// Minor Version
30+
// Build Number
31+
// Revision
32+
//
33+
// You can specify all the values or you can default the Build and Revision Numbers
34+
// by using the '*' as shown below:
35+
// [assembly: AssemblyVersion("1.0.*")]
36+
[assembly: AssemblyVersion("1.0.0.0")]
37+
[assembly: AssemblyFileVersion("1.0.0.0")]
38+

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LiveSplit.AVP2010
2+
=================
3+
4+
This is a [LiveSplit] component for Aliens vs. Predator (2010)
5+
6+
Features
7+
--------
8+
9+
* Removes load times.
10+
11+
Requirements
12+
------------
13+
14+
* Aliens vs. Predator (2010) - DirectX 11 only!!
15+
* LiveSplit 1.4+
16+
* .NET Framework 4
17+
18+
Credits
19+
-------
20+
21+
* [SuicideMachine](http://www.twitch.tv/suicidemachine)
22+
* Main code by [twitch.tv/fatalis_](http://www.twitch.tv/fatalis_)
23+
24+
[LiveSplit]:http://livesplit.org/

0 commit comments

Comments
 (0)