From 4c03498a1961c93d127b9e2f3dc50eafe777da5e Mon Sep 17 00:00:00 2001 From: Ham5ter Date: Tue, 6 Jan 2015 21:13:29 +0100 Subject: [PATCH] First Commit --- CAOS.sln | 20 ++++++ CAOS.v12.suo | Bin 0 -> 34816 bytes CAOS/CAOS.csproj | 53 ++++++++++++++++ CAOS/CaosInjector.cs | 105 ++++++++++++++++++++++++++++++++ CAOS/Properties/AssemblyInfo.cs | 36 +++++++++++ CAOS/bin/Release/CAOS.dll | Bin 0 -> 6656 bytes README.md | 12 ++++ 7 files changed, 226 insertions(+) create mode 100644 CAOS.sln create mode 100644 CAOS.v12.suo create mode 100644 CAOS/CAOS.csproj create mode 100644 CAOS/CaosInjector.cs create mode 100644 CAOS/Properties/AssemblyInfo.cs create mode 100644 CAOS/bin/Release/CAOS.dll create mode 100644 README.md diff --git a/CAOS.sln b/CAOS.sln new file mode 100644 index 0000000..d2ab297 --- /dev/null +++ b/CAOS.sln @@ -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 diff --git a/CAOS.v12.suo b/CAOS.v12.suo new file mode 100644 index 0000000000000000000000000000000000000000..9c11a9447d6aeb0913c94917f1cb78c18f25afdd GIT binary patch literal 34816 zcmeHQTX0*&89qu#F%Syjk^-e5LYi`kglx;Qog2|Laj_c{np7M~PjM z8D=`YJkSo)nO+{+DP`ybokHP-X?cTAhX)?WblR6bFl`^&PKO!VPNzIDkbd8;)><7O zNk@{CSk76`>g+jZ&;FPF_uqg2{m=3FceefcXRqGz7sHkg7@LicFI;1MLc8wM%Epa` zaV^ey?c)m$2k1z_Y*m@s5Aq zf8O^XZ+=SF7zf0Hancw8^f{E0#*)*cb+2tVHm$%X+v`@;ZhRSKh_6VKM%pMDr;Je} zi=$;chF=pnsq3Xmy?Te8#wOnW1(a(sid5*op#}Jlq3+fS{QGhI$c4Oej9-ts_f?+NANee^Rj68z;dE`fsN0A>z{sQt5>y>26=8FvaVHB4B@a66DFpjRC&+%^>70B~*N*_6 zW#ojVLrZ8LoU{Z)(@5ZIQB|ySr2W+@{LN_VKm0+8fvy7VKT=u5u?k(@Z}xj9;QLUC ziBPx2}q6LD_cAvA(Xf9fpGA8z66 z@;3n*bAr=S!s9sSN+b(OETbP9$v#op-3I?T4}Pse{}E#btDiAID;g5ERq2V6aZFgS zgi=540R5axX;ZnSpYt)-AWR8Bn*pWs_~W`~48IHD0oQ@LEI9Q&p9lS7{BaI&3%?(A zsVkZ6@MC~%g6pS@MPNaVU_l0TOyqOwHw^f+GdP^x!tX;}CI3qQaoxEHNg(CqgIhg7 z{X@Hj^P5}v?5kZIgh+(T9xsB@G~lN|a}MVv%r0_eEH$%THssS>zexU5rrg5U<-d{s zC2pKc8>M#i&j~d6^+t`hc#m|e)Z(LSQeDC3aZMU*v5`*TKRyN#n!@0xnx94~12Lr9 z51^Doxg^S*pl2YEoFtb~D~<*A5eyQRWPKV8Cn2~rBRGhHD3y#CU%&ssv;X~R;`QlQ zo__9)=-Z@BN4H~^o&SpQjh?^1_|k80-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Dzd)*tA4fYsve&& z+FY$Cmn<`1%FbkSS!+3%+uaKx9eB+PNLmEz!ud%Ig+i{pUJjz z$?A|=nLmY-nt@{qk*$neH=FWtEoNeg{}SL80Q3&zU!gnS#`$}gV!wssAMgg`1j>it zI(!x9L{v}sx|Nth`SHE>`hUsHlr0z(YGx%%$pNNoq;PHd5FlHZEPKmj@YSc&xw1Ju zZS<(F+eR2XxqkC??fm~o`czfdUH$I!kK(jxBDni1wf+_7e@~E!{+Cw&|D$?V^@=)g zbR>Tnfy6ZB@D-KL-a+u<|K+zm?eA(hzmagc*;?_|LYczE*ti8x9flJ M|3BJ$^vXK_KixlJRsaA1 literal 0 HcmV?d00001 diff --git a/CAOS/CAOS.csproj b/CAOS/CAOS.csproj new file mode 100644 index 0000000..db907b5 --- /dev/null +++ b/CAOS/CAOS.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {A4EF3E36-9042-44AE-AD4D-B644A4F7C719} + Library + Properties + CAOS + CAOS + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CAOS/CaosInjector.cs b/CAOS/CaosInjector.cs new file mode 100644 index 0000000..857e4b9 --- /dev/null +++ b/CAOS/CaosInjector.cs @@ -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; + } + } +} diff --git a/CAOS/Properties/AssemblyInfo.cs b/CAOS/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..45b5306 --- /dev/null +++ b/CAOS/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("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")] diff --git a/CAOS/bin/Release/CAOS.dll b/CAOS/bin/Release/CAOS.dll new file mode 100644 index 0000000000000000000000000000000000000000..9675d28e39a5a2f6def21b62dd749a082119984a GIT binary patch literal 6656 zcmeHLdu$v>8UJ=~?`h|n^R>>?$tF(SOHv=_M;;{){EXw0#IEm>xUC`CyW2SH-rZhy z_fj8eB3D34fs{UwTGXmVp@_B=sRcyCOQQS{K(tW)Kp=|xKuA;w1QiIWMNodkkG*lO7_r!B3h=Co4DbkwY_T9uM&l+>ZIv|2RtdUDya$R=;-@nNC^l8@}&PiJb@ zUL$!!lhj1i0#3l?KAJ+U;_1Ufv|O}h*KcNc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*FVpXlQzVui zmUtJZCBE=nlqQkyAS75Hm=PH{36e5bTcuDDMFrxOP%jdtM0+9cgLOIWK4|7E1${3K z_K&5L`9gsPHPap~&FDGDv;Ny0;85_|ZFGb^)$xh;RdqP7Dd79RpWBc4D?z}8BT;{xH&MZ0bOQ;Td zZLiBbSu_epl}7YZ#in#w&l$*^h>%>L#60!e?nyxXIma+dwX{!EN{&&~lSg#R2AiiS zqgn85AFkl~?WT2Gzk?Gbi)iXy^b-ZlEf3Of+j=ousAdeOpwBDT*h9K4k^|MHLim5e zn66kFk8~w*v8u zY{&|bQp}}Kfo3i^O*ZAAQzjLMB0qd*^4+mH{jE<&4m`c)!F$`Ey7?0ndhSD0M^^Q| zcDFCk62`L(PYlmBav-Xxk`zT(DXjWinnNhjfGW2%N0}Lt12QUE4unua;FChpkS{?p z9<7ed;${ekMl>456{aODa2f1TON<%UFeBQwRtZV~d}N-&*#c## zt5TaEijo}itFjdFqZx<*{1JtufFFR7Rdn{pg3WFIkUs?Ag31?^LQs%HqY|x79vaTn zUpCi!`(h97w%a7iM6a%kc!d#c;L}Jum1VL2@FeAeDBn>;T)UF;n?WR6*SxK#EEKYR&|O)n=-RAQ{KWA zjAS{VWmo=}%B*`W5h2~fZS~60)qZy%I)+=sP@!;8GfM6)MAyZ2h5Nn3*YV|79^qZ? ze?J5KJtTfMnp-$F?-k-3=Mp~a?Z-3OM|7{d#h8UQHY**WG#vvD(*#)gGs+)fMuJZcv<&d4uQ1XJLMMf|-M?PSat^3hd@t544~cVvPY45NM5CQS zd^3%~2A33GJ5t@o5%jU(*}P9(_})m>AGQ&OK1anTmW5hF9EX5>ZV|pa+_96C2VeYh zfO%*^p97Fj3++KfT&Ak&Mw)+qHO^`sY4e zFLE=Ez9u}Y;Lvg!yq@EHCVL%l};l{sCaf)Pev2 literal 0 HcmV?d00001 diff --git a/README.md b/README.md new file mode 100644 index 0000000..61e03b1 --- /dev/null +++ b/README.md @@ -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. \ No newline at end of file