- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
attach-to-console.pl.svn-base
上传用户:market2
上传日期:2018-11-18
资源大小:18786k
文件大小:3k
源码类别:
外挂编程
开发平台:
Windows_Unix
- #!/usr/bin/env perl
- #########################################################################
- # OpenKore - Socket interface
- #
- # Copyright (c) 2007 OpenKore development team
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #########################################################################
- # This program allows you to attach to a running OpenKore session that uses
- # the Socket interface.
- use strict;
- use FindBin qw($RealBin);
- use lib "$RealBin/..";
- use lib "$RealBin/../deps";
- use IO::Socket::UNIX;
- use ErrorHandler;
- use Globals qw($interface $quit %consoleColors);
- use Settings;
- use FileParsers qw(parseSectionedFile);
- use Interface::Console;
- use Bus::Messages qw(serialize);
- use Bus::MessageParser;
- my $socket;
- my $parser;
- start();
- sub start {
- if (!Settings::parseArguments()) {
- usage(1);
- }
- if (@ARGV != 1) {
- usage(1);
- }
- $socket = new IO::Socket::UNIX(
- Type => SOCK_STREAM,
- Peer => $ARGV[0]
- );
- if (!$socket) {
- print "Cannot connect to $ARGV[0]: $!n";
- exit 1;
- }
- $socket->send(serialize("set active"));
- $socket->flush();
- $parser = new Bus::MessageParser();
- Settings::addControlFile("consolecolors.txt", loader => [&parseSectionedFile, %consoleColors]);
- Settings::loadAll();
- $interface = new Interface::Console();
- $interface->mainLoop();
- }
- sub usage {
- print "Usage: attach-to-console.pl <SOCKET FILE>n";
- exit 1;
- }
- sub mainLoop {
- my $bits = '';
- vec($bits, fileno($socket), 1) = 1;
- if (select($bits, undef, undef, 0) > 0) {
- my ($data, $ID);
- $socket->recv($data, 1024 * 32);
- if (!defined($data) || length($data) == 0) {
- $quit = 1;
- } else {
- $parser->add($data);
- while (my $args = $parser->readNext($ID)) {
- if ($ID eq "output") {
- $interface->writeOutput($args->{type},
- $args->{message},
- $args->{domain});
- } elsif ($ID eq "title changed") {
- $interface->title($args->{title});
- } elsif ($ID eq "inputted") {
- $interface->writeOutput("message",
- "$args->{data}n",
- "input");
- }
- }
- }
- }
- if (defined(my $input = $interface->getInput(0))) {
- if ($input eq "detach") {
- $quit = 1;
- } else {
- my $message = serialize("input", { data => $input });
- $socket->send($message);
- $socket->flush();
- }
- }
- }