public void Invoke(IExecutionContext context) { var parentScope = context.Scope; var function = new InternalFunction(parentScope, _operations); context.Push(function.Pointer); }
private string GetFunctionDescription(Function f, int index) { string overloadIndicator = String.Empty; if (index == -1) { index = 0; if (f.Overloads.Length > 1) { overloadIndicator = String.Format(" <span style=\"color: #888888; font-size: 7.5pt\">(+{0} overloads)</span>", f.Overloads.Length - 1); } } InternalFunction iF = f.Overloads[index]; StringBuilder description = new StringBuilder(); description.Append(GetFormattedTypeString(iF.ReturnType) + " "); description.Append("<strong>" + f.Name + "</strong>("); for (int i = 0; i < iF.Arguments.Length; i++) { description.Append(GetFormattedTypeString(iF.Arguments[i].Type)); if (iF.Arguments[i].Name != String.Empty) { description.Append(" " + iF.Arguments[i].Name); } if (i != iF.Arguments.Length - 1) { description.Append(", "); } } description.Append(")" + overloadIndicator + "<br /><span style=\"color: #008800\">" + IntelliPrompt.EscapeMarkupText(iF.Description) + "</span>"); return(description.ToString()); }
public DecompilerLookup(ScriptEngineDefinition definition) { m_functionOpCodeLookup = new Dictionary <short, ExpressionReference>(); m_globalOpCodeLookup = new Dictionary <short, Global>(); // Type casters foreach (ExtendedTypeBase t in definition.ExtendedTypes) { foreach (InternalFunction f in t.ExplicitCasters) { m_functionOpCodeLookup.Add(f.OperationCode, new CasterReference(/*f*/)); } } // Special usage functions for (int i = 0; i < (int)FunctionSpecification.SupiFunctionCount; i++) { InternalFunction sf = definition.SpecificFunctions[i]; m_functionOpCodeLookup.Add(sf.OperationCode, new OperatorReference(sf)); } // Recurse through namespaces foreach (Namespace ns in definition.Namespaces) { CreateLookup(ns, null); } }
public static Dictionary <string, InternalFunction> GetFunctions(string path = "") { var result = new Dictionary <string, InternalFunction>(); var testAss = path == "" ? Assembly.GetExecutingAssembly() : Assembly.LoadFrom(path); foreach (var type in testAss.GetTypes()) { if (type.GetInterface(typeof(ILibrary).FullName) != null) { if (type.GetMethod("GetFunctions") != null) // TODO: DEPRECATED { var method = type.GetMethod("GetFunctions"); var rdict = (Dictionary <string, InternalFunction>) (method.Invoke(Activator.CreateInstance(type, null), null)); foreach (var entry in rdict) { result.Add(entry.Key, entry.Value); } } else { foreach (var myfunc in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { var theattr1 = myfunc.GetCustomAttributes(typeof(IntFunc), true); foreach (var theattr in theattr1.OfType <IntFunc>()) { var rfunc = new InternalFunction( (HassiumFunctionDelegate) Delegate.CreateDelegate(typeof(HassiumFunctionDelegate), myfunc)); result.Add(theattr.Name, rfunc); if (theattr.Alias != "") { result.Add(theattr.Alias, rfunc); } } } } } } return(result); }
public InternalClosure(string name, InternalFunction function) : base(name) { this.procedure = function; }
/// <summary> /// Sets the addresses for the internal functions. /// </summary> /// <param name="adrs">The addresses to set.</param> public void SetInternalFunctions(Objects.Addresses adrs) { if (!adrs.IsValid) return; InternalCaller caller = new InternalCaller(this.Client); this.FunctionLogout = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.Logout, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionAttack = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.Attack, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionChannelMessage = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.ChannelMessage, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionCloseContainer = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.CloseContainer, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionFightModes = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.FightModes, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionFollow = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.Follow, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionMoveItem = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.MoveItem, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionPrivateMessage = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.PrivateMessage, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionSay = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.Say, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionTurnEast = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.TurnEast, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionTurnNorth = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.TurnNorth, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionTurnSouth = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.TurnSouth, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionTurnWest = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.TurnWest, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionUseItem = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.UseItem, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionUseItemEx = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.UseItemOn, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionVipAdd = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.VipAdd, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionVipRemove = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.VipRemove, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkEast = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkEast, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkNorthEast = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkNorthEast, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkNorth = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkNorth, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkNorthWest = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkNorthWest, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkWest = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkWest, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkSouthWest = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkSouthWest, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkSouth = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkSouth, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionWalkSouthEast = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.WalkSouthEast, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionGetObjectProperty = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.GetObjectProperty, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionUseItemOnBattleList = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.UseItemOnBattleList, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionOpenParentContainer = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.OpenParentContainer, Caller = caller, CallingConvention = CallConvention.Cdecl }; this.FunctionPing = new InternalFunction() { Address = (IntPtr)adrs.InternalFunctions.Ping, Caller = caller, CallingConvention = CallConvention.Cdecl }; }
public PslOperatorUsageNode(InternalFunction @operator, List <NodeBase> operands) : base(operands) { m_operator = @operator; }
/// <summary> /// Loads a precompiled program from disk. /// </summary> /// <remarks> /// NOTE: We should employ some sort of checksum to verify bytecode integrity. /// </remarks> /// <param name="path"></param> public void Load(string path) { int i, count; Reset(); try { using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open))) { // Check signature i = reader.ReadInt32(); if (i != FileSignature) { throw new Exception(InvalidFileFormat); } // Read reserved int i = reader.ReadInt32(); if (i != 0) { throw new Exception(InvalidFileFormat); } // Read flags FileFlag flags = (FileFlag)reader.ReadInt32(); // Read bytecodes count = reader.ReadInt32(); ByteCodes = new int[count]; for (i = 0; i < count; i++) { ByteCodes[i] = reader.ReadInt32(); } // Read functions count = reader.ReadInt32(); List <Function> functions = new List <Function>(count); for (i = 0; i < count; i++) { string name = reader.ReadString(); FunctionType type = (FunctionType)reader.ReadInt32(); if (type == FunctionType.Internal) { var function = new InternalFunction(name, null); functions.Add(function); } else if (type == FunctionType.Intrinsic) { var function = new IntrinsicFunction(name); functions.Add(function); } else // FunctionType.User { var function = new UserFunction(name, 0) { IP = reader.ReadInt32(), NumVariables = reader.ReadInt32(), NumParameters = reader.ReadInt32(), }; functions.Add(function); } } Functions = functions.ToArray(); // Read global variables count = reader.ReadInt32(); Variables = new Variable[count]; for (i = 0; i < count; i++) { Variables[i] = ReadVariable(reader); } // Read literals count = reader.ReadInt32(); Literals = new Variable[count]; for (i = 0; i < count; i++) { Literals[i] = ReadVariable(reader); } // Read line numbers if (flags.HasFlag(FileFlag.HasLineNumbers)) { count = reader.ReadInt32(); LineNumbers = new int[count]; for (i = 0; i < count; i++) { LineNumbers[i] = reader.ReadInt32(); } Debug.Assert(LineNumbers.Length == ByteCodes.Length); } // Fixup internal functions foreach (var function in functions.OfType <InternalFunction>()) { if (InternalFunctions.InternalFunctionLookup.TryGetValue(function.Name, out InternalFunctionInfo info)) { function.Action = info.Action; function.MinParameters = info.MinParameters; function.MaxParameters = info.MaxParameters; } else { throw new Exception($"Internal intrinsic function \"{function.Name}\" not found"); } } } } catch (Exception ex) { // Clear to known state if error Reset(); throw ex; } }
public void ReadFromToolExe(BinaryReader br) { short functionCount, globalCount; uint functionTablePointer, globalTablePointer, typeArrayPointer; switch (m_majorVersion) { case GameMajorVersion.Halo1: functionCount = 545; functionTablePointer = 0x002EC220; globalCount = 495; globalTablePointer = 0x00328B00; typeArrayPointer = 0x00722C8C; break; case GameMajorVersion.Halo2: functionCount = 924; functionTablePointer = 0x005ECFE0; globalCount = 704; globalTablePointer = 0x005EDE6C; // this is not the pointer table, fix typeArrayPointer = 0; break; default: throw new Exception("Not a supported version."); } m_functions = new InternalFunction[functionCount]; for (short i = 0; i < functionCount; i++) { br.BaseStream.Position = functionTablePointer + i * 4; br.BaseStream.Position = br.ReadUInt32() - 0x400000; short returnType = br.ReadInt16(); br.BaseStream.Position += 2; uint namePointer = br.ReadUInt32(); br.BaseStream.Position += 8; uint descriptionPointer = br.ReadUInt32(); uint argumentHelpPointer = br.ReadUInt32(); br.BaseStream.Position += 2; short argumentCount = br.ReadInt16(); Argument[] args = new Argument[argumentCount]; for (short j = 0; j < argumentCount; j++) { args[j] = new Argument(String.Empty, br.ReadInt16(), String.Empty); } br.BaseStream.Position = namePointer - 0x400000; string name = StringOps.ReadCString(br); string description = String.Empty; if (descriptionPointer != 0) { br.BaseStream.Position = descriptionPointer - 0x400000; description = StringOps.ReadCString(br); } //unused: string argumentHelp = String.Empty; if (argumentHelpPointer != 0) { br.BaseStream.Position = argumentHelpPointer - 0x400000; //unused: argumentHelp = StringOps.ReadCString(br); } m_functions[i] = new InternalFunction(name, i, returnType, description, args); } m_globals = new InternalGlobal[globalCount]; for (short i = 0; i < globalCount; i++) { br.BaseStream.Position = globalTablePointer + i * 4; br.BaseStream.Position = br.ReadUInt32() - 0x400000; uint namePointer = br.ReadUInt32(); short type = br.ReadInt16(); br.BaseStream.Position = namePointer - 0x400000; string name = StringOps.ReadCString(br); m_globals[i] = new InternalGlobal(name, i, type); } uint typeTablePointer = typeArrayPointer + 4; br.BaseStream.Position = typeArrayPointer; int typeCount = br.ReadInt32() - (int)IntegralValueType.IntegralValueTypeCount; m_types = new ExtendedTypeBase[typeCount]; for (short i = 0; i < typeCount; i++) { short typeIndex = (short)(i + IntegralValueType.IntegralValueTypeCount); br.BaseStream.Position = typeTablePointer + typeIndex * 4; br.BaseStream.Position = br.ReadUInt32() - 0x400000; string name = StringOps.ReadCString(br); Dictionary <string, short> objectReferences = new Dictionary <string, short>(); // f**k, how to handle Hud.Navpoints["red_flag"] with the dot/namespacing dealy switch (name) { case "trigger_volume": m_types[i] = new BlockReferenceType(name, "TriggerVolumes", typeIndex, typeIndex, BlockSourceTag.Scenario); break; case "navpoint": m_types[i] = new BlockReferenceType(name, "Navpoints", typeIndex, typeIndex, BlockSourceTag.HudGlobals); break; default: m_types[i] = new BlockReferenceType(name, ScriptingStringOps.ToPslFormatting(name, null) + 's', typeIndex, typeIndex, BlockSourceTag.Scenario); break; } } // enumerations 0x00656F4C }
public OperatorReference(InternalFunction @operator) { m_operation = @operator; }