Ejemplo n.º 1
0
 public static void WriteEmpty(PythonWriter pw)
 {
     pw.WriteTuple(4);
     pw.WriteNoneStruct();
     pw.WriteNoneStruct();
     pw.WriteNoneStruct();
     pw.WriteNoneStruct();
 }
Ejemplo n.º 2
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(4);
     pw.WriteInt(Red);
     pw.WriteInt(Green);
     pw.WriteInt(Blue);
     pw.WriteInt(Alpha);
 }
Ejemplo n.º 3
0
        public void Write(PythonWriter pw)
        {
            pw.WriteInt(SlotId);

            pw.WriteTuple(2);
            pw.WriteInt(ClassId);
            pw.WriteStruct(Color);
        }
Ejemplo n.º 4
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteList(ContextIdList.Count);
     foreach (var contextId in ContextIdList)
     {
         pw.WriteUInt(contextId);
     }
 }
Ejemplo n.º 5
0
        public void Write(PythonWriter pw)
        {
            pw.WriteInt((int)SlotId);

            pw.WriteTuple(3);
            pw.WriteUInt(Class);
            pw.WriteStruct(Color);

            Color.WriteEmpty(pw);
        }
Ejemplo n.º 6
0
        private static string processNodes(PythonWriter parentWriter, IEnumerable <SyntaxNode> nodes)
        {
            PythonWriter pyWriter = new PythonWriter(parentWriter.IndentSize);

            foreach (var node in nodes)
            {
                pyWriter.Append(processNode(pyWriter, node));
            }

            return(pyWriter.ToString());
        }
Ejemplo n.º 7
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(5);
     pw.WriteUInt(ContextId);
     pw.WriteUInt(InstanceId);
     pw.WriteUInt(Version);
     pw.WriteTuple(3);
     pw.WriteDouble(Position.X);
     pw.WriteDouble(Position.Y);
     pw.WriteDouble(Position.Z);
     pw.WriteDouble(Rotation);
 }
Ejemplo n.º 8
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(2);
     pw.WriteTuple(3);
     pw.WriteDouble(Position.X);
     pw.WriteDouble(Position.Y);
     pw.WriteDouble(Position.Z);
     pw.WriteTuple(4);
     pw.WriteDouble(Rotation.X);
     pw.WriteDouble(Rotation.Y);
     pw.WriteDouble(Rotation.Z);
     pw.WriteDouble(Rotation.W);
 }
Ejemplo n.º 9
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(1);
            pw.WriteDictionary(9);

            pw.WriteString("SlotId");
            pw.WriteUInt(SlotId);

            pw.WriteString("IsSelected");
            pw.WriteInt(IsSelected ? 1 : 0);

            pw.WriteString("BodyData");
            pw.WriteStruct(BodyData);

            pw.WriteString("CharacterData");
            pw.WriteStruct(CharacterData);

            pw.WriteString("AppearanceData");
            pw.WriteDictionary(AppearanceData.Count);

            foreach (var appearance in AppearanceData)
            {
                appearance.Value.Write(pw);
            }

            pw.WriteString("UserName");
            if (FamilyName != null)
            {
                pw.WriteUnicodeString(FamilyName);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("GameContextId");
            if (GameContextId == 0)
            {
                pw.WriteNoneStruct();
            }
            else
            {
                pw.WriteUInt(GameContextId);
            }

            pw.WriteString("LoginData");
            pw.WriteStruct(LoginData);

            pw.WriteString("ClanData");
            pw.WriteStruct(ClanData);
        }
Ejemplo n.º 10
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(10);
     pw.WriteUnicodeString(Name);
     pw.WriteUInt(MapContextId);
     pw.WriteUInt(ExpPoints);
     pw.WriteInt(ExpLevel);
     pw.WriteUInt(Body);
     pw.WriteUInt(Mind);
     pw.WriteUInt(Spirit);
     pw.WriteUInt(Class);
     pw.WriteUInt(CloneCredits);
     pw.WriteInt((int)RaceId);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Traverse C# tokens, convert C# syntax to (Iron)Python syntax
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        private static string processRawToken(PythonWriter parentWriter, SyntaxToken token)
        {
            PythonWriter pyWriter = new PythonWriter(parentWriter.IndentSize);

            switch (token.Kind())
            {
            case SyntaxKind.ThisKeyword:
                // replace 'this' keyword to python self
                pyWriter.Append("self");
                break;

            case SyntaxKind.NewKeyword:
                // no 'new' keyword
                // skip
                break;

            case SyntaxKind.SemicolonToken:
                // semicolon -> end of expression
                pyWriter.NewLine();
                break;

            case SyntaxKind.NumericLiteralToken:
                // Float in C#, like '6F'
                pyWriter.Append(token.Text.Replace("F", ""));
                break;

            case SyntaxKind.OpenBraceToken:
                // Left Brace in C#
                // skip
                break;

            case SyntaxKind.CloseBraceToken:
                // Right Brace in C#
                // skip
                break;

            case SyntaxKind.TrueKeyword:
                pyWriter.Append("True");
                break;

            case SyntaxKind.FalseKeyword:
                pyWriter.Append("False");
                break;

            default:
                pyWriter.Append(token.Text);
                break;
            }
            return(pyWriter.ToString());
        }
Ejemplo n.º 12
0
        public void Write(PythonWriter pw)
        {
            pw.WriteTuple(3);
            pw.WriteUInt(NumLogins);
            pw.WriteUInt(TotalTimePlayed);

            if (LastLogin.HasValue && LastLogin.Value < DateTime.UtcNow)
            {
                pw.WriteUInt((uint)Math.Floor((DateTime.UtcNow - LastLogin.Value).TotalMinutes));
            }
            else
            {
                pw.WriteUInt(0);
            }
        }
Ejemplo n.º 13
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(3);
            pw.WriteUInt(EntityId);
            pw.WriteInt(ClassId);

            if (EntityData != null)
            {
                // todo
            }
            else
            {
                pw.WriteNoneStruct();
            }
        }
Ejemplo n.º 14
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(5);
            pw.WriteUnicodeString(FamilyName);
            pw.WriteBool(HasCharacters);
            pw.WriteUInt(UserId);

            pw.WriteTuple(EnabledRaceList.Count);

            foreach (var race in EnabledRaceList)
            {
                pw.WriteInt((int)race);
            }

            pw.WriteBool(CanSkipBootcamp);
        }
Ejemplo n.º 15
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(6);

            pw.WriteList(StateIds.Count);
            foreach (var stateId in StateIds)
            {
                pw.WriteUInt(stateId);
            }

            pw.WriteDouble(Rotation);
            pw.WriteULong(TrackingTargetEntityId);
            pw.WriteDouble(MovementModifier);
            pw.WriteUInt(DesiredPostureId);
            pw.WriteBool(IsHoldingCombatMode);
        }
Ejemplo n.º 16
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(3);
            pw.WriteUInt(EntityId);
            pw.WriteInt((int)ClassId);

            /*
             * These packets will be called on the newly created entity. It behaves the same as if we've sent them separately. Order matters!
             *
             * Possible packets that can be appended here: (Not all of them are reasonable to include...)
             *   + PhysicalEntity
             *     - BodyAttributes
             *     - WorldLocationDescriptor
             *     - WorldPlacementDescriptor
             *     - IsTargetable
             *     - ServerSkeleton
             *     - ExamineResults
             *     - GameEffectAttached
             *     - GameEffectAttachFailed
             *     - GameEffectTick
             *     - CallGameEffectMethod
             *     - GameEffectDetached
             *     - GameEffects
             *     - GameEffectUpdateTooltip
             *     - PerformObjectAbility
             *   + CharacterSelectionPod augmentation:
             *        - CharacterInfo
             *        - CloneCreditsChanged
             *   + Other augmentations: ...
             */
            if (EntityData.Count > 0)
            {
                pw.WriteList(EntityData.Count);

                foreach (var packet in EntityData)
                {
                    pw.WriteTuple(2);
                    pw.WriteInt((int)packet.Opcode);

                    packet.Write(pw);
                }
            }
            else
            {
                pw.WriteNoneStruct();
            }
        }
Ejemplo n.º 17
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteDictionary(AppearanceData.Count);
     foreach (var t in AppearanceData)
     {
         var appearance = t.Value;
         pw.WriteInt((int)appearance.SlotId);
         pw.WriteTuple(2);
         pw.WriteUInt((uint)appearance.Class);
         pw.WriteTuple(4);
         pw.WriteInt(appearance.Color.Red);
         pw.WriteInt(appearance.Color.Green);
         pw.WriteInt(appearance.Color.Blue);
         pw.WriteInt(appearance.Color.Alpha);
     }
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Executes the code and redirects the results into a writer object.
        /// </summary>
        /// <param name="code">Source code to be executed.</param>
        /// <param name="writer">The result is written here.</param>
        /// <returns>Object that encapsulates the compiles code.</returns>
        public object ExecuteCode(string code, PythonWriter writer)
        {
            ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
            Object o = null;
            try
            {
                CompiledCode compiled = source.Compile();
                object sys = runtime.GetSysModule();
                engine.Operations.SetMember(sys, "stdout", writer);
                engine.Operations.SetMember(sys, "stderr", writer);

                o = compiled.Execute(scope);

                // TODO: allow canceling operation
            }
            catch (Exception e)
            {
                ExceptionOperations eo = engine.GetService<ExceptionOperations>();
                string error = eo.FormatException(e);
                writer.write(error);
            }
            return o;
        }
Ejemplo n.º 19
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteUInt(DesiredCrouchState);
 }
Ejemplo n.º 20
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteUnicodeString(Name);
 }
Ejemplo n.º 21
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(2);
     pw.WriteUInt(Id);
     pw.WriteUnicodeString(Name);
 }
Ejemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentWriter"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private static string processNode(PythonWriter parentWriter, SyntaxNode node)
        {
            PythonWriter pyWriter = new PythonWriter(parentWriter.IndentSize);

            switch (node.Kind())
            {
            case SyntaxKind.InvocationExpression:
                // Looking for interface cast invocation (e.g. the ISupportInitialize interface)
                var error = false;
                try
                {
                    var node_cast = node
                                    .ChildNodes().Where(n => n.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Single()
                                    .ChildNodes().Where(n => n.IsKind(SyntaxKind.ParenthesizedExpression)).Single()
                                    .ChildNodes().Where(n => n.IsKind(SyntaxKind.CastExpression)).Single();
                    var node_qn = node_cast
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.QualifiedName)).Single();
                    var node_pe = node_cast
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.ParenthesizedExpression)).Single();
                    var node_in = node
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Single()
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.IdentifierName)).Single();

                    // TODO: make sure that there's nothing in the invocation has 0 argument

                    /**
                     *
                     *  C#:
                     *      ((node_qn)(node_pe)).node_in()
                     *
                     *  -> Python:
                     *      (node_qn).node_in(node_pe)
                     *
                     *  Reference:
                     *      https://mail.python.org/pipermail/ironpython-users/2006-February/001800.html
                     *
                     **/
                    pyWriter.Append(String.Format("{0}.{1}({2})",
                                                  processNode(pyWriter, node_qn),
                                                  processNode(pyWriter, node_in),
                                                  processNode(pyWriter, node_pe)
                                                  ));
                }
                catch (InvalidOperationException)
                {
                    error = true;
                }
                if (error)
                {
                    pyWriter.Append(processNodes(pyWriter, node.ChildNodes()));
                }
                break;

            case SyntaxKind.ArrayCreationExpression:

                var _nodeAT = from _n in node.ChildNodes().OfType <ArrayTypeSyntax>() select _n;
                var _nodeQN = from _n in _nodeAT.Single().ChildNodes().OfType <QualifiedNameSyntax>() select _n;
                var _nodeIE = from _n in node.DescendantNodes().OfType <InitializerExpressionSyntax>() select _n;

                pyWriter.Append(String.Format("System.Array[{0}]([{1}])",
                                              _nodeQN.Single().ToFullString(),        // e.g. "System.Windows.Forms.ToolStripItem"
                                              processNode(pyWriter, _nodeIE.Single()) // e.g. "self.a1, self.a2, self.a3"
                                              ));

                break;

            case SyntaxKind.AddAssignmentExpression:
            // TODO
            // break;
            default:
                foreach (var nodeOrToken in node.ChildNodesAndTokens())
                {
                    if (nodeOrToken.IsNode)
                    {
                        pyWriter.Append(processNode(pyWriter, nodeOrToken.AsNode()));
                    }
                    else
                    {
                        pyWriter.Append(processRawToken(pyWriter, nodeOrToken.AsToken()));
                    }
                }
                break;
            }
            return(pyWriter.ToString());
        }
Ejemplo n.º 23
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(1);
            pw.WriteDictionary(9);

            pw.WriteString("SlotId");
            pw.WriteUInt(SlotId);

            pw.WriteString("IsSelected");
            pw.WriteInt(SlotId == 0 ? 1 : 0);

            pw.WriteString("BodyData");
            if (BodyData != null && !_empty)
            {
                pw.WriteTuple(2);
                pw.WriteInt(BodyData.GenderClassId);
                pw.WriteDouble(BodyData.Scale);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("CharacterData");
            if (CharacterData != null && !_empty)
            {
                pw.WriteTuple(10); // TODO
                pw.WriteUnicodeString("CharName");
                pw.WriteInt(1);    // pos
                pw.WriteInt(41);   // xpptrs
                pw.WriteInt(10);   // xplvl
                pw.WriteInt(111);  // body
                pw.WriteInt(12);   //mind
                pw.WriteInt(21);   // spirit
                pw.WriteInt(2);    // class id
                pw.WriteInt(3);    // clone credits
                pw.WriteInt(3);    // raceId
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("AppearanceData");
            if (AppearanceData != null && !_empty)
            {
                // TODO
                var count = 0;
                for (var i = 0; i < 21; ++i)
                {
                    if (true) // TODO:
                    {
                        ++count;
                    }
                }

                pw.WriteDictionary(count);

                for (var i = 0; i < 21; ++i)
                {
                    if (true)
                    {
                        pw.WriteInt(i + 1); // equipment slot id
                        pw.WriteTuple(2);
                        pw.WriteInt(0);     // classId

                        pw.WriteTuple(4);
                        pw.WriteInt(0); // hueR
                        pw.WriteInt(0); // hueG
                        pw.WriteInt(0); // hueB
                        pw.WriteInt(0); // hueA
                    }// TODO: else nonstruct?
                }
            }
            else
            {
                pw.WriteTuple(0);
            }

            pw.WriteString("UserName");
            if (UserName != null && !_empty)
            {
                pw.WriteUnicodeString(UserName);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("GameContextId");
            if (!_empty)
            {
                pw.WriteInt(GameContextId);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("LoginData");
            if (LoginData != null && !_empty)
            {
                pw.WriteTuple(3);
                pw.WriteInt(0); // num logins
                pw.WriteInt(0); // total time played
                pw.WriteInt(0); // time since last played
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("ClanData");
            if (ClanData != null && !_empty)
            {
                pw.WriteTuple(2);
                pw.WriteInt(0);                     // clan id
                pw.WriteUnicodeString("Clan name"); // clan name
            }
            else
            {
                pw.WriteNoneStruct();
            }
        }
Ejemplo n.º 24
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteInt((int)Result);
 }
Ejemplo n.º 25
0
 public void NewLine(int indentation)
 {
     sb.AppendLine();
     sb.Append(PythonWriter.GetIndentationString(indentation));
 }
Ejemplo n.º 26
0
 public void NewLine()
 {
     sb.AppendLine();
     sb.Append(PythonWriter.GetIndentationString(IndentSize));
 }
Ejemplo n.º 27
0
        public static int Convert(string csFile, string outFile)
        {
            SyntaxTree tree = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile));

            var root = (CompilationUnitSyntax)tree.GetRoot();

            var formClass = (from _n in root.DescendantNodes().OfType <ClassDeclarationSyntax>()
                             select _n).Single();

            var formName = formClass.Identifier.ValueText;

            // // Select the initial_components method
            //
            // var _nodeICMethod = (from methoddef in formClass.DescendantNodes().OfType<MethodDeclarationSyntax>()
            //                 where methoddef.Identifier.ValueText == "InitializeComponent"
            //                 select methoddef).Single();

            PythonWriter pyWriter = new PythonWriter();

            pyWriter.Append($@"
""""""
Auto generated by formdesingercs2ipy.
IronPython WinForm class from Visual Studio Form Designer. 
DO NOT MODIFY THIS FILE MANUALLY. 
""""""

import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')

import System
from System.Drawing import *
from System.Windows.Forms import *

class {formName}(Form):
    def __init__(self):
        """"""
        Create child controls and initialize form
        """"""
        self.initialize_component()
    
    def initialize_component(self):
        """"""
        Windows Form Designer generated code, auto converted by formdesingercs2ipy
        """"""
        {generateFunctionBodyInitializeComponent(2, root)}
        
        
if __name__ == '__main__':
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
        
    form = {formName}()
    Application.Run(form)
            ");

            // Write file
            Console.WriteLine(pyWriter.ToString());
            File.WriteAllText(outFile, pyWriter.ToString());

            return(0);
        }
Ejemplo n.º 28
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteUInt(ContextId);
 }
Ejemplo n.º 29
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteULong(EntityId);
 }
Ejemplo n.º 30
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteInt(LangId);
 }
Ejemplo n.º 31
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(2);
     pw.WriteUInt((uint)GenderClassId);
     pw.WriteDouble(Scale);
 }