// Target code (based on v1.1.130102): // UIUtils.ShowNumberSelectMinMax(this.curItem.itemId, 0, Mathf.Max(a, 0), 1, TextMgr.GetStr(100401, -1), new Action<int>(this.StartAutomataResult), (Action) (() => {}), true, (int) totalTime, itemNameStr); // Replacement (transpiled) code: // UIUtils.ShowNumberSelectMinMax(this.curItem.itemId, 0, Mathf.Max(a, 0), Mathf.Max(a, 0), TextMgr.GetStr(100401, -1), new Action<int>(this.StartAutomataResult), (Action) (() => {}), true, (int) totalTime, itemNameStr); private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SearchState state = SearchState.INITIAL; List <CodeInstruction> saved_inst = new List <CodeInstruction>(); foreach (CodeInstruction inst in instructions) { if (state != SearchState.DFLT_1 && state != SearchState.TXTMGR_ID) { yield return(inst); } switch (state) { case SearchState.THIS: if (inst.opcode == OpCodes.Ldarg_0) { saved_inst.Clear(); state++; } break; case SearchState.CURITEM: if (inst.operand?.ToString()?.Contains("curItem") == true) { state++; } else { ULogger.LogTrace("Fallback from {0} state; opcode={1}", state.ToString("G"), inst.opcode.ToString()); state = SearchState.INITIAL; } break; case SearchState.ITEMID: if (inst.operand?.ToString()?.Contains("itemId") == true) { state++; } else { ULogger.LogTrace("Fallback from {0} state; opcode={1}", state.ToString("G"), inst.opcode.ToString()); state = SearchState.INITIAL; } break; case SearchState.MIN_0: if (inst.opcode == OpCodes.Ldc_I4_0) { state++; } else { ULogger.LogTrace("Fallback from {0} state; opcode={1}", state.ToString("G"), inst.opcode.ToString()); state = SearchState.INITIAL; } break; case SearchState.LOCAL_VAR: case SearchState.PARAM_0: if (inst.opcode.ToString().StartsWith("Ldloc", true, null) || inst.opcode == OpCodes.Ldc_I4_0) { saved_inst.Add(inst); state++; } else { ULogger.LogTrace("Fallback from {0} state; opcode={1}", state.ToString("G"), inst.opcode.ToString()); state = SearchState.INITIAL; } break; case SearchState.CALL_MAX: if ((inst.opcode == OpCodes.Call || inst.opcode == OpCodes.Callvirt) && (inst.operand?.ToString()?.Contains(" Max(") == true)) { saved_inst.Add(inst); state++; } else { ULogger.LogTrace("Fallback from {0} state; opcode={1}, operand={2}", state.ToString("G"), inst.opcode.ToString(), inst.operand?.ToString()); state = SearchState.INITIAL; } break; case SearchState.DFLT_1: if (inst.opcode == OpCodes.Ldc_I4_1) { state++; } else { ULogger.LogTrace("Fallback from {0} state; opcode={1}", state.ToString("G"), inst.opcode.ToString()); yield return(inst); state = SearchState.INITIAL; } break; case SearchState.TXTMGR_ID: var opVal = (inst.operand as int?); if (opVal == 100401) { foreach (CodeInstruction newinst in saved_inst) { yield return(newinst); } state++; } else { ULogger.LogTrace("Fallback from {0} state; operand={1}, opVal={1}", state.ToString("G"), inst.operand.ToString(), opVal); state = SearchState.INITIAL; } yield return(inst); break; } } if (state != SearchState.END) { ULogger.LogError("Unable to patch default crafting number; game or plugin version is outdated!"); } else { ULogger.LogTrace("Successfully patched"); } }
private void ComposeLogItemBody(Body itemBody) { if (itemBody == null) { throw new ArgumentNullException("itemBody"); } using (TextWriter textWriter = itemBody.OpenTextWriter(BodyFormat.TextHtml)) { StringBuilder stringBuilder = new StringBuilder(); using (StreamReader streamReader = new StreamReader(Assembly.GetAssembly(typeof(SearchMailboxExecuter)).GetManifestResourceStream("SimpleLogMailTemplate.htm"))) { stringBuilder.Append(streamReader.ReadToEnd()); } SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LastStartTime, this.searchMailboxExecuter.SearchStartTime); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchQuery, this.SearchQuery); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.TargetMailbox, this.targetUser.Id.DomainUserName()); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchDumpster, this.SearchDumpster); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LogLevel, this.LogLevel); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SourceRecipients, (from x in this.searchMailboxExecuter.SearchMailboxCriteria.SearchUserScope select x.Id.DomainUserName()).AggregateOfDefault((string s, string x) => s + ", " + x)); ADObjectId adobjectId = null; base.TryGetExecutingUserId(out adobjectId); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.LastRunBy, (adobjectId == null) ? string.Empty : adobjectId.DomainUserName()); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.NumberMailboxesToSearch, this.searchMailboxExecuter.SearchMailboxCriteria.SearchUserScope.Length); if (this.DeleteContent.IsPresent) { if (base.ParameterSetName == "Mailbox") { SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchOperation, Strings.CopyAndDeleteOperation); } else { SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchOperation, Strings.DeleteOperation); } } else if (this.LogOnly.IsPresent) { SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchOperation, Strings.LogOnlyOperation); } else { SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.SearchOperation, Strings.CopyOperation); } string str = this.errorMessages.AggregateOfDefault((string s, string x) => s + ", " + x); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.Errors, str.ValueOrDefault(Strings.LogMailNone)); long num = 0L; ByteQuantifiedSize byteQuantifiedSize = ByteQuantifiedSize.Zero; if (this.searchMailboxExecuter.SearchState != SearchState.InProgress) { foreach (SearchMailboxResult searchMailboxResult in this.searchMailboxExecuter.GetSearchResult()) { num += (long)searchMailboxResult.ResultItemsCount; byteQuantifiedSize += searchMailboxResult.ResultItemsSize; } } SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultNumber, num); SearchMailbox.ReplaceLogFieldTags(stringBuilder, Globals.LogFields.ResultSize, byteQuantifiedSize); SearchState searchState = (this.searchMailboxExecuter.SearchState == SearchState.InProgress) ? SearchState.Failed : this.searchMailboxExecuter.SearchState; stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailHeader.ToLabelTag(), Strings.LogMailSimpleHeader(searchState.ToString())); stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailSeeAttachment.ToLabelTag(), Strings.LogMailSeeAttachment); stringBuilder = stringBuilder.Replace(Globals.LogFields.LogMailFooter.ToLabelTag(), Strings.LogMailFooter); textWriter.Write(stringBuilder.ToString()); } }