public static Parser <char, T> ToParserIO <T>(this Parser <T> self) => inp => { var res = self(new PString(new string(inp.Value), inp.Index, inp.EndIndex, inp.Pos, inp.DefPos, inp.Side, inp.UserState)); var state = res.Reply.State; var pstr = new PString <char>( state.Value.ToCharArray(), state.Index, state.EndIndex, state.Pos, state.DefPos, state.Side, state.UserState); var reply = res.Reply; return(new ParserResult <char, T>( res.Tag, new Reply <char, T>( reply.Tag, reply.Result, pstr, reply.Error))); };
/// <summary>Asks for the user's opinion on a place after the place has been stated. Typical string: "what's it like in England" /// <remarks>Depends on Article keywords.</remarks></summary> /// <param name="position">Preposition/article describing the place.</param><param name="place">The name of the place.</param> public static PString[] AskPlaceOpinion(string position, string place) { string article = ""; if (position.Contains(" a")) { position = position.Replace(" a", ""); article = "your"; } else if (position.Contains(" an")) { position = position.Replace(" an", ""); article = "your"; } else if (position.Contains(" some")) { position = position.Replace(" some", ""); article = "your"; } else if (position.Contains(" the")) { position = position.Replace(" the", ""); article = "the"; } string aPlace = (article == "" ? place : article + ' ' + place); string inPlace = position + ' ' + aPlace; PString[] s = new PString[5]; s[0] = new PString("do you enjoy being " + inPlace, 20); s[1] = new PString("what's it like " + inPlace, 30); s[2] = new PString("do you like " + aPlace, 30); s[3] = new PString("what do you think of " + aPlace, 12); s[4] = new PString("what's your opinion of" + aPlace, 8); return(s); }
/// <summary> /// Sets value for key. If item exists for alt key, replace it. /// </summary> public static void SetOrChange(this PDictionary dict, string key, string altKey, string value) { var keyItem = dict.Get <PString> (key); var altItem = dict.Get <PString> (altKey); if (keyItem == null) { if (altItem != null) { dict.ChangeKey(altItem, key); altItem.Value = value; } else { dict[key] = new PString(value); } } else { if (altItem != null) { dict.Remove(altKey); } keyItem.Value = value; } }
bool Clear(ref PObject plist) { if (Type != null) { switch (Type.ToLowerInvariant()) { case "string": plist = new PString(string.Empty); break; case "array": plist = new PArray(); break; case "dict": plist = new PDictionary(); break; case "bool": plist = new PBoolean(false); break; case "real": plist = new PReal(0); break; case "integer": plist = new PNumber(0); break; case "date": plist = new PDate(DateTime.Now); break; case "data": plist = new PData(new byte[1]); break; default: Log.LogError(7045, null, $"Unrecognized Type: {Type}"); return(false); } } else { plist = PObject.Create(plist.Type); } return(true); }
private static void remoteExecCommand(PString pstr) { PString outCmd = new PString($"remoteex {pstr.pstr}"); GameAPI.Game_Request(CmdId.Request_ConsoleCommand, 0, outCmd); GameAPI.Console_Write($"remoteex: {outCmd.ToString()}"); GameAPI.Game_Request(CmdId.Request_ConsoleCommand, 0, new Eleon.Modding.PString("SAY 'remote exex command'")); }
public static void SetIfNotPresent(this PDictionary dict, string key, string value) { var str = dict.Get <PString> (key); if (str == null || string.IsNullOrEmpty(str.Value)) { dict[key] = new PString(value); } }
public PString Replace(int pos, int n, string after) { PString ret = new PString(PapillonPINVOKE.PString_Replace__SWIG_1(swigCPtr, pos, n, after), false); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public PString Replace(string before, string after) { PString ret = new PString(PapillonPINVOKE.PString_Replace__SWIG_0(swigCPtr, before, after), false); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool GetQueryValue(string key, PString value) { bool ret = PapillonPINVOKE.PUri_GetQueryValue__SWIG_0(swigCPtr, key, PString.getCPtr(value)); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public virtual PResult GetModelName(PString modelName) { PResult ret = new PResult(PapillonPINVOKE.PDescriberInterface_GetModelName(swigCPtr, PString.getCPtr(modelName)), true); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public PResult GetBoundAddress(PString boundAddress) { PResult ret = new PResult(PapillonPINVOKE.PSocket_GetBoundAddress(swigCPtr, PString.getCPtr(boundAddress)), true); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static PString GetUIMainStoryboardFile(this PDictionary dict, bool ipad) { PString str = null; if (ipad) { str = dict.Get <PString> (ManifestKeys.UIMainStoryboardFileIPad); } return(str ?? dict.Get <PString> (ManifestKeys.UIMainStoryboardFile)); }
public static PResult ChangeRootDir(PString path, string oldRoot, string newRoot) { PResult ret = new PResult(PapillonPINVOKE.PPath_ChangeRootDir__SWIG_1(PString.getCPtr(path), oldRoot, newRoot), true); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public PResult Receive(PString message) { PResult ret = new PResult(PapillonPINVOKE.PSocket_Receive__SWIG_0(swigCPtr, PString.getCPtr(message)), true); if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
internal int EncodeSYMBBlock(SYMBHeader *header, RSAREntryList entries, RSARNode node) { int len = 0; int count = entries._strings.Count; VoidPtr baseAddr = (VoidPtr)header + 8, dataAddr; bint * strEntry = (bint *)(baseAddr + 0x18); PString pStr = (byte *)strEntry + (count << 2); //Strings header->_stringOffset = 0x14; strEntry[-1] = entries._strings.Count; foreach (string s in entries._strings) { *strEntry++ = (int)(pStr - baseAddr); pStr.Write(s, 0, s.Length + 1); pStr += s.Length + 1; } dataAddr = pStr; //Sounds header->_maskOffset1 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup(header, (SYMBMaskHeader *)dataAddr, entries._sounds, node, 0); //Player Info header->_maskOffset2 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup(header, (SYMBMaskHeader *)dataAddr, entries._playerInfo, node, 1); //Groups header->_maskOffset3 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup(header, (SYMBMaskHeader *)dataAddr, entries._groups, node, 2); //Banks header->_maskOffset4 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup(header, (SYMBMaskHeader *)dataAddr, entries._banks, node, 3); int temp = (int)dataAddr - (int)header; len = temp.Align(0x20); //Fill padding byte *p = (byte *)dataAddr; for (int i = temp; i < len; i++) { *p++ = 0; } //Set header header->_header._tag = SYMBHeader.Tag; header->_header._length = len; return(len); }
PString MergeEntitlementString(PString pstr, MobileProvision profile) { string TeamIdentifierPrefix; string AppIdentifierPrefix; if (string.IsNullOrEmpty(pstr.Value)) { return((PString)pstr.Clone()); } if (profile == null) { if (!warnedTeamIdentifierPrefix && pstr.Value.Contains("$(TeamIdentifierPrefix)")) { Log.LogWarning(null, null, null, Entitlements, 0, 0, 0, 0, "Cannot expand $(TeamIdentifierPrefix) in Entitlements.plist without a provisioning profile."); warnedTeamIdentifierPrefix = true; } if (!warnedAppIdentifierPrefix && pstr.Value.Contains("$(AppIdentifierPrefix)")) { Log.LogWarning(null, null, null, Entitlements, 0, 0, 0, 0, "Cannot expand $(AppIdentifierPrefix) in Entitlements.plist without a provisioning profile."); warnedAppIdentifierPrefix = true; } } if (profile != null && profile.ApplicationIdentifierPrefix.Count > 0) { AppIdentifierPrefix = profile.ApplicationIdentifierPrefix[0] + "."; } else { AppIdentifierPrefix = string.Empty; } if (profile != null && profile.TeamIdentifierPrefix.Count > 0) { TeamIdentifierPrefix = profile.TeamIdentifierPrefix[0] + "."; } else { TeamIdentifierPrefix = AppIdentifierPrefix; } var customTags = new Dictionary <string, string> (StringComparer.OrdinalIgnoreCase) { { "TeamIdentifierPrefix", TeamIdentifierPrefix }, { "AppIdentifierPrefix", AppIdentifierPrefix }, { "CFBundleIdentifier", BundleIdentifier }, }; var expanded = StringParserService.Parse(pstr.Value, customTags); return(new PString(expanded)); }
private void getHelp(ChatInfo data, PString subcommand) { var msg = new IdMsgPrio() { msg = helpMessage, id = data.playerId, prio = 1 }; var cmd = new APICmd(CmdId.Request_ShowDialog_SinglePlayer, msg); broker.ExecuteCommand(cmd); }
internal static int EncodeSYMBBlock(SYMBHeader *header, RSAREntryList entries) { int count = entries._count; VoidPtr baseAddr = (VoidPtr)header + 8, dataAddr; int len; bint * strEntry = (bint *)(baseAddr + 0x18); PString pStr = (byte *)strEntry + (count << 2); //Strings header->_stringOffset = 0x14; strEntry[-1] = entries._strings.Count; foreach (string s in entries._strings) { *strEntry++ = (int)(pStr - baseAddr); pStr.Write(s, 0, s.Length + 1); pStr += s.Length + 1; } dataAddr = pStr; //Sounds header->_maskOffset1 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup((SYMBMaskHeader *)dataAddr, entries._sounds); //Types header->_maskOffset2 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup((SYMBMaskHeader *)dataAddr, entries._types); //Groups header->_maskOffset3 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup((SYMBMaskHeader *)dataAddr, entries._groups); //Banks header->_maskOffset4 = (int)(dataAddr - baseAddr); dataAddr += EncodeMaskGroup((SYMBMaskHeader *)dataAddr, entries._banks); len = ((int)baseAddr).Align(0x20); //Fill padding byte *p = (byte *)dataAddr; for (int i = dataAddr - header; i < len; i++) { *p++ = 0; } //Set header header->_tag = SYMBHeader.Tag; header->_length = len; return(len); }
/// <summary> /// Asks the user a question, with a chance to address the user by name. Defaults to 0% if the user's name is unknown. /// </summary> /// <param name="question">The question to be asked.</param> /// <param name="useNameChance">The percentage chance to address the user by name. Does not apply if the user's name is unknown.</param> private string WriteQuestion(string message, int useNameChance) { if (!knowsName) { return(message + '?'); } string pComma = Util.RandomPick(Write.RandomComma); PString[] s = new PString[3]; s[0] = new PString(message + '?', 100 - useNameChance); s[1] = new PString(userName + ", " + message + '?', useNameChance / 2); s[2] = new PString(message + pComma + userName + '?', useNameChance / 2); return(Util.RandomPick(s)); }
public unsafe string FindName(string name) { int index = -1; if (string.IsNullOrEmpty(name)) { name = "NewNode"; } int len = name.Length; sbyte * charList = stackalloc sbyte[len + 3]; PString pStr = charList; for (int i = 0; i < len; i++) { charList[i] = (sbyte)name[i]; } Top: if (index < 0) { charList[len] = 0; } else { charList[len] = (sbyte)((index % 10) | 0x30); if (index < 10) { charList[len + 1] = 0; } else { charList[len + 1] = (sbyte)((index / 10) | 0x30); charList[len + 2] = 0; } } index++; foreach (ResourceNode node in Children) { if (pStr == node.Name) { goto Top; } } return(new String(charList)); }
/// <summary> /// Makes a statement, with a chance to address the user by name. Defaults to 0% if the user's name is unknown. /// </summary> /// <param name="message">The bot's statement.</param> /// <param name="useNameChance">The percentage chance to address the user by name. Does not apply if the user's name is unknown.</param> private string WriteStatement(string message, int useNameChance) { string endMark = Util.RandomPick(Write.EndPhrase); if (!knowsName) { return(message + endMark); } string pComma = Util.RandomPick(Write.RandomComma); PString[] s = new PString[2]; s[0] = new PString(message + endMark, 100 - useNameChance); s[1] = new PString(message + pComma + userName + endMark, useNameChance); return(Util.RandomPick(s)); }
private static void debugEntitySpawning(PString prefabName) { EntitySpawnInfo info = new EntitySpawnInfo { playfield = "Akua", pos = new PVector3(11.5354891F, 58.5829468F, -11.8831434F), rot = new PVector3(0F, 139.371F, 0F), name = "BA_Alien", type = 2, factionGroup = 2, factionId = 0, prefabName = "Infested-Test" }; var cmd = new APICmd(CmdId.Request_Entity_Spawn, info); broker.HandleCall(cmd); }
private void withdrawUpgradePoints(ChatInfo data, PString subcommand) { int value; value = int.TryParse(subcommand.pstr, out value) ? value : -1; if (value < 0) { return; } log(() => $"*** beginning transfer of {value}"); this.transferBalance(data.playerId, value, TransactionType.UpgradePoints, x => { log(() => "***** transfer response"); string balanceMessage; string factionMessage; if (x.succeeded) { balanceMessage = $"withdrawal successful\nyour crew has a balance of {x.crewBalance} points;\nyour personal balance is {x.playerBalance} points"; factionMessage = $"{x.playerName} has withdrawn {value} points from the crew bank"; var facmsg = new IdMsgPrio() { id = x.crewAccount, msg = factionMessage, prio = (byte)(x.succeeded ? 1 : 0) }; var cmd = new APICmd(CmdId.Request_InGameMessage_Faction, facmsg); broker.ExecuteCommand(cmd); } else { balanceMessage = $"withdrawal failed: {x.reason}"; } var msg = new IdMsgPrio() { id = data.playerId, msg = balanceMessage, prio = (byte)(x.succeeded ? 1:0) }; var outmsg = new APICmd(CmdId.Request_InGameMessage_SinglePlayer, msg); broker.ExecuteCommand(outmsg); }); }
public static void Request_Playfield_Entity_List(PString arg, Action <PlayfieldEntityList> callback = null, Action <ErrorInfo> onError = null) { Action <CmdId, object> wiredCallback = null; if (callback != null) { wiredCallback = (_, val) => callback((PlayfieldEntityList)val); } var apiCmd = new GenericAPICommand( CmdId.Request_Playfield_Entity_List, arg, wiredCallback, onError ?? noOpErrorHandler ); Broker.Execute(apiCmd); }
public static void Request_GlobalStructure_Update(PString arg, Action callback = null, Action <ErrorInfo> onError = null) { Action <CmdId, object> wiredCallback = null; if (callback != null) { wiredCallback = (_, val) => callback(); } var apiCmd = new GenericAPICommand( CmdId.Request_GlobalStructure_Update, arg, wiredCallback, onError ?? noOpErrorHandler ); Broker.Execute(apiCmd); }
private static void testBroker(PString pstr) { GameAPI.Console_Write($"**** executing broker test"); var cmd = new APICmd(CmdId.Request_ConsoleCommand, new Eleon.Modding.PString("SAY 'broker test'")); broker.HandleCall <object>(cmd, (x, y) => { switch (x) { case CmdId.Event_Ok: GameAPI.Console_Write("test successful"); break; case CmdId.Event_Error: GameAPI.Console_Write("test error"); break; } }); }
private void convertCredits(ChatInfo data, PString subcommand) { int value; value = int.TryParse(subcommand.pstr, out value) ? value : -1; if (value < 0) { return; } var result = convertPointsToCredits(data.playerId, value); var msg = new IdMsgPrio() { id = data.playerId, msg = $"you converted {result.amountRequested} points to credits", prio = 1 }; var outmsg = new APICmd(CmdId.Request_InGameMessage_SinglePlayer, msg); broker.ExecuteCommand(outmsg); }
static IPhoneDeviceType ParseDeviceTypeFromString(PString value) { // Sometimes this is a string of the form '1,2' as found // in the xcode plist files for xcode 4.4.1 var devices = IPhoneDeviceType.NotSet; var str = (string)value; if (!string.IsNullOrEmpty(str)) { foreach (var v in str.Split(',')) { AppleDeviceFamily family; if (Enum.TryParse <AppleDeviceFamily> (v, out family)) { devices |= family.ToDeviceType(); } } } return(devices); }
private void checkCrewBalance(ChatInfo data, PString subcommand) { var playerId = new Id(data.playerId); var cmd = new APICmd(CmdId.Request_Player_Info, playerId); broker.ExecuteCommand <PlayerInfo>(cmd, (cmdId, playerInfo) => { var crewAccount = SafeGetAccount(AccountType.Crew, playerInfo.factionId, playerInfo); var crewBalance = crewAccount.balances[ResourceType.Points]; var personalAccount = SafeGetAccount(playerInfo); var personalBalance = personalAccount.balances[ResourceType.Points]; var balanceMessage = $"your crew has a balance of {crewBalance} points;\nyour personal balance is {personalBalance} points"; var msg = new IdMsgPrio() { id = playerInfo.entityId, msg = balanceMessage, prio = 1 }; var outmsg = new APICmd(CmdId.Request_InGameMessage_SinglePlayer, msg); broker.ExecuteCommand(outmsg); }); }
public void TestSetArrayValue() { var plist = new PDictionary(); var primary = new PDictionary(); var icons = new PDictionary(); var files = new PArray(); plist.Add("CFBundleIdentifier", "com.microsoft.set-array-value"); plist.Add("CFBundleIcons", icons); icons.Add("CFBundlePrimaryIcon", primary); primary.Add("CFBundleIconFiles", files); files.Add("icon0"); files.Add("icon1"); files.Add("icon2"); var expected = (PDictionary)plist.Clone(); files[0] = new PString("icon"); TestExecuteTask(plist, PropertyListEditorAction.Set, ":CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles:0", "string", "icon0", expected); // Note: this will fail due to the index being out of range TestExecuteTask(plist, PropertyListEditorAction.Set, ":CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles:3", "string", "icon3", null); }
public Environment() { Output = new Output(); EmptyArgs = new SArgs(this); True = new LBoolean(this, true); False = new LBoolean(this, false); Undefined = new LUndefined(this); Null = new LNull(this); GlobalObject = new BGlobal(this); GlobalEnvironment = new SLexicalEnvironment(this, new SObjectEnvironmentRecord(this, GlobalObject, false), null); MathObject = new BMath(this); JsonObject = new BJson(this); ObjectConstructor = new CObject(this); FunctionConstructor = new CFunction(this); ArrayConstructor = new CArray(this); StringConstructor = new CString(this); BooleanConstructor = new CBoolean(this); NumberConstructor = new CNumber(this); DateConstructor = new CDate(this); RegExpConstructor = new CRegExp(this); ErrorConstructor = new CError(this); EvalErrorConstructor = new CEvalError(this); RangeErrorConstructor = new CRangeError(this); ReferenceErrorConstructor = new CReferenceError(this); SyntaxErrorConstructor = new CSyntaxError(this); TypeErrorConstructor = new CTypeError(this); UriErrorConstructor = new CUriError(this); ObjectPrototype = new PObject(this); FunctionPrototype = new PFunction(this); ArrayPrototype = new PArray(this); StringPrototype = new PString(this); BooleanPrototype = new PBoolean(this); NumberPrototype = new PNumber(this); DatePrototype = new PDate(this); RegExpPrototype = new PRegExp(this); ErrorPrototype = new PError(this); EvalErrorPrototype = new PEvalError(this); RangeErrorPrototype = new PRangeError(this); ReferenceErrorPrototype = new PReferenceError(this); SyntaxErrorPrototype = new PSyntaxError(this); TypeErrorPrototype = new PTypeError(this); UriErrorPrototype = new PUriError(this); GlobalObject.Initialize(); MathObject.Initialize(); JsonObject.Initialize(); ObjectConstructor.Initialize(); FunctionConstructor.Initialize(); ArrayConstructor.Initialize(); StringConstructor.Initialize(); BooleanConstructor.Initialize(); NumberConstructor.Initialize(); DateConstructor.Initialize(); RegExpConstructor.Initialize(); ErrorConstructor.Initialize(); EvalErrorConstructor.Initialize(); RangeErrorConstructor.Initialize(); ReferenceErrorConstructor.Initialize(); SyntaxErrorConstructor.Initialize(); TypeErrorConstructor.Initialize(); UriErrorConstructor.Initialize(); ObjectPrototype.Initialize(); FunctionPrototype.Initialize(); ArrayPrototype.Initialize(); StringPrototype.Initialize(); BooleanPrototype.Initialize(); NumberPrototype.Initialize(); DatePrototype.Initialize(); RegExpPrototype.Initialize(); ErrorPrototype.Initialize(); EvalErrorPrototype.Initialize(); RangeErrorPrototype.Initialize(); ReferenceErrorPrototype.Initialize(); SyntaxErrorPrototype.Initialize(); TypeErrorPrototype.Initialize(); UriErrorPrototype.Initialize(); }