-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CAOS", "CAOS\CAOS.csproj", "{A4EF3E36-9042-44AE-AD4D-B644A4F7C719}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A4EF3E36-9042-44AE-AD4D-B644A4F7C719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A4EF3E36-9042-44AE-AD4D-B644A4F7C719}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A4EF3E36-9042-44AE-AD4D-B644A4F7C719}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A4EF3E36-9042-44AE-AD4D-B644A4F7C719}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{A4EF3E36-9042-44AE-AD4D-B644A4F7C719}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CAOS</RootNamespace> | ||
<AssemblyName>CAOS</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</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.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="CaosInjector.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Text; | ||
using System.IO.MemoryMappedFiles; | ||
using System.Threading; | ||
|
||
namespace CAOS | ||
{ | ||
public class CaosInjector | ||
{ | ||
static Mutex Mutex; | ||
static MemoryMappedFile MemFile; | ||
static MemoryMappedViewAccessor MemViewAccessor; | ||
static EventWaitHandle ResultEventHandle; | ||
static EventWaitHandle RequestRventHandle; | ||
private string GameName; | ||
public CaosInjector(string GameName) | ||
{ | ||
this.GameName = GameName; | ||
InitInjector(); | ||
CloseInjector(); | ||
} | ||
private void InitInjector() | ||
{ | ||
try | ||
{ | ||
Mutex = Mutex.OpenExisting(this.GameName + "_mutex"); | ||
MemFile = MemoryMappedFile.OpenExisting(this.GameName + "_mem"); | ||
MemViewAccessor = MemFile.CreateViewAccessor(); | ||
ResultEventHandle = EventWaitHandle.OpenExisting(this.GameName + "_result"); | ||
RequestRventHandle = EventWaitHandle.OpenExisting(this.GameName + "_request"); | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
} | ||
private void CloseInjector() | ||
{ | ||
RequestRventHandle.Close(); | ||
ResultEventHandle.Close(); | ||
MemViewAccessor.Dispose(); | ||
MemFile.Dispose(); | ||
Mutex.Close(); | ||
} | ||
public CaosResult AddScriptToScriptorium(int Familiy, int Genus, int Species, int Event, string Script) | ||
{ | ||
return ExecuteCaosGetResult(Script, "scrp " + Familiy + " " + Genus + " " + Species + " " + Event); | ||
} | ||
public CaosResult ExecuteCaosGetResult(string CaosAsString, string Action = "execute") | ||
{ | ||
InitInjector(); | ||
byte[] CaosBytes = Encoding.UTF8.GetBytes(Action + "\n" + CaosAsString + "\n"); | ||
int BufferPosition = 24; | ||
Mutex.WaitOne(1000); | ||
foreach (byte Byte in CaosBytes) | ||
{ | ||
MemViewAccessor.Write(BufferPosition, Byte); | ||
BufferPosition++; | ||
} | ||
RequestRventHandle.Set(); | ||
ResultEventHandle.WaitOne(5000); | ||
int ResultSize = MemViewAccessor.ReadInt16(12); | ||
byte[] ResultBytes = new byte[ResultSize]; | ||
int ResultCode = Convert.ToInt16(MemViewAccessor.ReadByte(8)); | ||
int ProcessID = Convert.ToInt16(MemViewAccessor.ReadByte(4)); | ||
for (int i = 0; i < ResultSize; i++) | ||
{ | ||
ResultBytes[i] = MemViewAccessor.ReadByte(24 + i); | ||
} | ||
for (int i = 0; i < CaosBytes.Length; i++) | ||
{ | ||
MemViewAccessor.Write(24 + i, (byte)0); | ||
} | ||
for (int i = 0; i < ResultSize; i++) | ||
{ | ||
MemViewAccessor.Write(24 + i, (byte)0); | ||
} | ||
Mutex.ReleaseMutex(); | ||
CloseInjector(); | ||
Thread.Sleep(50); | ||
return new CaosResult(ResultCode, Encoding.UTF8.GetString(ResultBytes), ProcessID); | ||
} | ||
public int ProcessID() | ||
{ | ||
Mutex.WaitOne(); | ||
int ProcessID = MemViewAccessor.ReadInt16(4); | ||
Mutex.ReleaseMutex(); | ||
return ProcessID; | ||
} | ||
} | ||
public class CaosResult | ||
{ | ||
private bool failed; | ||
public bool Failed { get { return failed; } } | ||
private int processid; | ||
public int ProcessID { get { return processid; } } | ||
private string content; | ||
public string Content { get { return content; } } | ||
public CaosResult(int Failed, string Content, int ProcessID) | ||
{ | ||
this.failed = Convert.ToBoolean(Failed); | ||
this.content = Content; | ||
this.processid = ProcessID; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("CAOS")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("CAOS")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[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("45bc6fa6-3962-4754-a0e7-78b38d0a6a5d")] | ||
|
||
// 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")] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# README # | ||
|
||
CAOS Class Library is a Library writen in C# which can be used to inject CAOS Code into the Games "Creatures 3" and "Docking Station". | ||
It uses a Shared Memory interface, provided by the Game-Engine, to Communicate with the game, for More Infromatioen on that Topic, visit: http://double.co.nz/creatures/developer/sharedmemory.htm | ||
|
||
|
||
### License ### | ||
The CAOS Console, and all it's Parts are Licensed under the [GPL3](https://gnu.org/licenses/gpl-3.0)! | ||
|
||
### How do I set it up? ### | ||
|
||
Just Download the Visual Studio Project and compile it with Visual Studio. |