Browse Source

Initial code commit.

master
atom0s 7 years ago
commit
c9edbcf99a
  1. 221
      .gitignore
  2. 28
      Greed.sln
  3. 5
      Greed/Exports.def
  4. 144
      Greed/Greed.h
  5. 168
      Greed/Greed.vcxproj
  6. 32
      Greed/Greed.vcxproj.filters
  7. 565
      Greed/main.cpp
  8. 2596
      Greed/rapidxml/rapidxml.hpp
  9. 174
      Greed/rapidxml/rapidxml_iterators.hpp
  10. 421
      Greed/rapidxml/rapidxml_print.hpp
  11. 122
      Greed/rapidxml/rapidxml_utils.hpp
  12. 1
      README.md

221
.gitignore vendored

@ -0,0 +1,221 @@ @@ -0,0 +1,221 @@
# ---> VisualStudio
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
/Ashita.exp
/Ashita.lib

28
Greed.sln

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Greed", "Greed\Greed.vcxproj", "{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Debug|x64.ActiveCfg = Debug|x64
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Debug|x64.Build.0 = Debug|x64
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Debug|x86.ActiveCfg = Debug|Win32
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Debug|x86.Build.0 = Debug|Win32
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Release|x64.ActiveCfg = Release|x64
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Release|x64.Build.0 = Release|x64
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Release|x86.ActiveCfg = Release|Win32
{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

5
Greed/Exports.def

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
LIBRARY "Greed"
EXPORTS
GetInterfaceVersion
CreatePluginInfo
CreatePlugin

144
Greed/Greed.h

@ -0,0 +1,144 @@ @@ -0,0 +1,144 @@
/**
* Copyright (c) 2011-2014 - Ashita Development Team
*
* Ashita 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 3 of the License, or
* (at your option) any later version.
*
* Ashita 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.
*
* You should have received a copy of the GNU General Public License
* along with Ashita. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ASHITA_Greed_H_INCLUDED__
#define __ASHITA_Greed_H_INCLUDED__
#if defined (_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/**
* @brief Required includes for an extension.
*/
#include "C:\Ashita 3\plugins\ADK\Ashita.h"
#include "rapidxml\rapidxml.hpp"
#include "rapidxml\rapidxml_utils.hpp"
#include <map>
#include <stdint.h>
#define SPACING 3
#define PADDING 3
#define GreedSIZE 36
#define FONTSIZE 10
#define FADERANGE 400
// buffer I/O macros
#define RBUFP(p,pos) (((uint8_t*)(p)) + (pos))
#define RBUFB(p,pos) (*(uint8_t*)RBUFP((p),(pos)))
#define RBUFW(p,pos) (*(uint16_t*)RBUFP((p),(pos)))
#define RBUFL(p,pos) (*(uint32_t*)RBUFP((p),(pos)))
#define RBUFF(p,pos) (*(float*)RBUFP((p),(pos)))
#define WBUFP(p,pos) (((uint8_t*)(p)) + (pos))
#define WBUFB(p,pos) (*(uint8_t*)WBUFP((p),(pos)))
#define WBUFW(p,pos) (*(uint16_t*)WBUFP((p),(pos)))
#define WBUFL(p,pos) (*(uint32_t*)WBUFP((p),(pos)))
#define WBUFU(p,pos) (*(uint64_t*)WBUFP((p),(pos)))
#define WBUFF(p,pos) (*(float*)WBUFP((p),(pos)))
/**
* @brief Global copy of our plugin data.
*/
plugininfo_t* g_PluginInfo = NULL;
static std::vector<std::string> jobs = { "", "WAR", "MNK", "WHM", "BLM", "RDM", "THF", "PLD", "DRK",
"BST", "BRD", "RNG", "SAM", "NIN", "DRG", "SMN", "BLU", "COR", "PUP", "DNC", "SCH", "GEO", "RUN" };
static const std::vector<D3DCOLOR> jobColors = { D3DCOLOR_ARGB(255, 120, 120, 120), D3DCOLOR_ARGB(255, 140, 0, 0), D3DCOLOR_ARGB(255, 255, 177, 32),
D3DCOLOR_ARGB(255, 255, 255, 255), D3DCOLOR_ARGB(255, 68, 68, 68), D3DCOLOR_ARGB(255, 255, 0, 0), D3DCOLOR_ARGB(255, 0, 164, 49),
D3DCOLOR_ARGB(255, 198, 198, 0), D3DCOLOR_ARGB(255, 116, 0, 145), D3DCOLOR_ARGB(255, 165, 153, 10), D3DCOLOR_ARGB(255, 184, 128, 10),
D3DCOLOR_ARGB(255, 224, 0, 230), D3DCOLOR_ARGB(255, 234, 100, 0), D3DCOLOR_ARGB(255, 119, 0, 0), D3DCOLOR_ARGB(255, 130, 17, 255),
D3DCOLOR_ARGB(255, 79, 196, 0), D3DCOLOR_ARGB(255, 50, 66, 217), D3DCOLOR_ARGB(255, 136, 68, 0), D3DCOLOR_ARGB(255, 244, 98, 98),
D3DCOLOR_ARGB(255, 15, 190, 220), D3DCOLOR_ARGB(255, 0, 123, 145), D3DCOLOR_ARGB(255, 255, 70, 255), D3DCOLOR_ARGB(255, 255, 255, 255) };
struct config_t
{
uint8_t spacing;
uint8_t padding;
uint8_t Greedsize;
uint8_t fontsize;
float faderange;
Ashita::FrameAnchor anchor;
float x;
float y;
uint8_t rf;
uint8_t gf;
uint8_t bf;
uint8_t rb;
uint8_t gb;
uint8_t bb;
bool jobColored;
};
/**
* @brief Our Main Plugin Class
*
* @note The main class of your plugin MUST use PluginBase as a base class. This is the
* internal base class that Ashita uses to communicate with your plugin!
*/
class Greed : IPlugin
{
/**
* @brief Internal class variables.
*/
IAshitaCore* m_AshitaCore;
ILogManager* m_LogManager;
DWORD m_PluginId;
IDirect3DDevice8* m_Direct3DDevice;
private:
rapidxml::xml_document<> settings;
rapidxml::file<>* xmlFile;
std::map<IFontObject*, uint32_t> targIdMap;
void LoadSettings();
config_t config;
public:
/**
* @brief Constructor and deconstructor.
*/
Greed(void);
virtual ~Greed(void);
/**
* @brief GetPluginData implementation.
*/
plugininfo_t GetPluginInfo(void);
/**
* @brief PluginBase virtual overrides.
*/
bool Initialize(IAshitaCore* core, ILogManager* log, uint32_t id);
void Release(void);
bool Direct3DInitialize(IDirect3DDevice8* device);
void Direct3DRelease(void);
void Direct3DPreRender(void);
void Direct3DRender(void);
void onClick(int, IFontObject*, float, float);
};
Greed* g_Greed = NULL;
/**
* @brief Required Plugin Exports
*/
__declspec(dllexport) double __stdcall GetInterfaceVersion(void);
__declspec(dllexport) void __stdcall CreatePluginInfo(plugininfo_t* lpBuffer);
__declspec(dllexport) IPlugin* __stdcall CreatePlugin(void);
#endif // __ASHITA_Greed_H_INCLUDED__

168
Greed/Greed.vcxproj

@ -0,0 +1,168 @@ @@ -0,0 +1,168 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{76CFA8DA-57D5-44B7-BFE6-A7DEDA51F9B2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Greed</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\..\..\..\..\..\..\..\Ashita 3\plugins</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;GREED_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>Exports.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;GREED_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>Exports.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Full</Optimization>
<FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;GREED_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<StringPooling>true</StringPooling>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>Exports.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;GREED_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>Exports.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Greed.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="Exports.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

32
Greed/Greed.vcxproj.filters

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Greed.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Exports.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
</Project>

565
Greed/main.cpp

@ -0,0 +1,565 @@ @@ -0,0 +1,565 @@
/**
* Copyright (c) 2011-2014 - Ashita Development Team
*
* Ashita 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 3 of the License, or
* (at your option) any later version.
*
* Ashita 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.
*
* You should have received a copy of the GNU General Public License
* along with Ashita. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Greed.h"
#include <algorithm>
#undef max
#undef min
D3DCOLOR darken(D3DCOLOR color)
{
return D3DCOLOR_ARGB(((color & 0xFF000000) >> 24), ((color & 0xFF0000) >> 16) / 3, ((color & 0xFF00) >> 8) / 3, (color & 0xFF) / 3);
}
D3DCOLOR brighten(D3DCOLOR color)
{
uint8_t alpha = (color & 0xFF000000) >> 24;
uint8_t r = (color & 0xFF0000) >> 16;
uint8_t g = (color & 0xFF00) >> 8;
uint8_t b = (color & 0xFF);
return D3DCOLOR_ARGB(alpha, r > 225 ? 255 : r + 30, g > 225 ? 255 : g + 30, b > 225 ? 255 : b + 30);
}
/**
* @brief Constructor and Deconstructor
*/
Greed::Greed(void)
: m_AshitaCore(NULL)
, m_PluginId(0)
, m_Direct3DDevice(NULL)
{ }
Greed::~Greed(void)
{ }
/**
* @brief Obtains the plugin data for this plugin.
*
* @return The PluginData structure for this plugin.
*/
plugininfo_t Greed::GetPluginInfo(void)
{
return (*g_PluginInfo);
}
/**
* @brief Initializes our plugin. This is the main call that happens when your plugin is loaded.
*
* @param ashitaCore The main Ashita Core object interface to interact with Ashita.
* @param scriptEngine The main script engine object interface to interact with the script engine.
* @param dwPluginId The base address of your plugin. This is used as the ID.
*
* @return True on success, false otherwise.
*
* @note If your plugin returns false here, it will be unloaded immediately!
*/
bool Greed::Initialize(IAshitaCore* core, ILogManager* log, uint32_t id)
{
// Store the variables we are passed..
this->m_AshitaCore = core;
this->m_PluginId = id;
this->m_LogManager = log;
g_Greed = this;
LoadSettings();
return true;
}
/**
* @brief Releases this plugin. This is called when your plugin is unloaded.
*
* @note Your plugin should cleanup all its data here before it unloads. Anything such as:
* - Font objects.
* - Gui objects.
* - Bindings to the script engine (if you extended it any).
*/
void Greed::Release(void)
{
}
/**
* @brief Direct3D initialize call to prepare this plugin for Direct3D calls.
*
* @param lpDevice The Direct3D device currently wrapped by Ashita.
*
* @return True on success, false otherwise.
*
* @note Plugins that do not return true on this call will not receive any other
* Direct3D calls listed below!
*/
bool Greed::Direct3DInitialize(IDirect3DDevice8* device)
{
this->m_Direct3DDevice = device;
IFontObject* base = m_AshitaCore->GetFontManager()->Create("GreedBase");
base->SetFontFamily("Consolas");
base->SetFontHeight(10);
base->SetAutoResize(false);
base->GetBackground()->SetColor(D3DCOLOR_ARGB(0x60, 0x00, 0x00, 0x00));
base->GetBackground()->SetVisibility(true);
base->GetBackground()->SetWidth(308);
base->GetBackground()->SetHeight(config.Greedsize + config.spacing * 2);
base->SetAnchor((uint32_t)config.anchor);
base->SetAnchorParent((uint32_t)config.anchor);
base->SetText("");
base->SetPositionX(config.x);
base->SetPositionY(config.y);
base->SetVisibility(true);
IFontObject* prev = base;
IFontObject* rowBase = NULL;
for (int i = 0; i < 18; i++)
{
std::string texPath = m_AshitaCore->GetAshitaInstallPathA();
texPath.append("\\Resources\\Greed\\gradient.tga");
char alias[32];
sprintf_s(alias, sizeof alias, "GreedBG%d", i);
IFontObject* bg = m_AshitaCore->GetFontManager()->Create(alias);
bg->SetAutoResize(false);
bg->GetBackground()->SetColor(D3DCOLOR_ARGB(0xFF, config.rb, config.gb, config.bb));
bg->GetBackground()->SetWidth(config.Greedsize);
bg->GetBackground()->SetHeight(config.Greedsize);
bg->GetBackground()->SetVisibility(true);
bg->SetParent(prev);
bg->SetAnchor((uint32_t)config.anchor);
auto right = config.anchor & Ashita::FrameAnchor::Right;
auto bottom = config.anchor & Ashita::FrameAnchor::Bottom;
if (prev == base)
{
bg->SetAnchorParent((uint32_t)config.anchor);
bg->SetPositionX(right ? -config.spacing : config.spacing);
bg->SetPositionY(bottom ?
-config.spacing - (config.Greedsize + config.padding) * (i / 6) :
config.spacing + (config.Greedsize + config.padding) * (i / 6));
rowBase = bg;
}
else if (i == 6 || i == 12)
{
bg->SetParent(rowBase);
bg->SetAnchorParent(((int32_t)config.anchor ^ (int32_t)Ashita::FrameAnchor::Bottom));
bg->SetPositionX(0);
bg->SetPositionY(bottom ? -config.padding : config.padding);
rowBase = bg;
}
else
{
bg->SetAnchorParent(((int32_t)config.anchor ^ (int32_t)Ashita::FrameAnchor::Right));
bg->SetPositionX(right ? -config.padding : config.padding);
bg->SetPositionY(0);
}
bg->SetVisibility(true);
bg->SetMouseEventFunction([](int type, void* font, float xPos, float yPos){g_Greed->onClick(type, (IFontObject*)font, xPos, yPos); });
bg->GetBackground()->SetTextureFromFile(texPath.c_str());
sprintf_s(alias, sizeof alias, "GreedFG%d", i);
IFontObject* fg = m_AshitaCore->GetFontManager()->Create(alias);
fg->SetAutoResize(false);
fg->GetBackground()->SetColor(D3DCOLOR_ARGB(0xFF, config.rf, config.gf, config.bf));
fg->GetBackground()->SetWidth(config.Greedsize);
fg->GetBackground()->SetHeight(config.Greedsize);
fg->GetBackground()->SetVisibility(true);
fg->SetParent(bg);
fg->SetAnchor((uint32_t)Ashita::FrameAnchor::BottomLeft);
fg->SetAnchorParent((uint32_t)Ashita::FrameAnchor::BottomLeft);
fg->SetPositionX(0);
fg->SetPositionY(0);
fg->SetVisibility(true);
fg->GetBackground()->SetTextureFromFile(texPath.c_str());
sprintf_s(alias, sizeof alias, "GreedTX%d", i);
IFontObject* tx = m_AshitaCore->GetFontManager()->Create(alias);
tx->SetAutoResize(false);
tx->SetFontFamily("Consolas");
tx->SetFontHeight(config.fontsize);
tx->SetText("");
tx->SetColor(D3DCOLOR_ARGB(0xFF, config.rb, config.gb, config.bb));
tx->GetBackground()->SetVisibility(false);
tx->SetParent(bg);
tx->SetAnchor((uint32_t)Ashita::FrameAnchor::BottomLeft);
tx->SetAnchorParent((uint32_t)Ashita::FrameAnchor::BottomLeft);
tx->SetPositionX(config.padding);
tx->SetPositionY(-config.Greedsize / 2 - (5 * config.fontsize) / 6);
tx->SetVisibility(true);
sprintf_s(alias, sizeof alias, "GreedIndicatorTopLeft%d", i);
IFontObject* br = m_AshitaCore->GetFontManager()->Create(alias);
br->SetAutoResize(false);
br->GetBackground()->SetColor(D3DCOLOR_ARGB(0xFF, 0x80, 0x80, 0x00));
br->GetBackground()->SetWidth(config.Greedsize / 6);
br->GetBackground()->SetHeight(config.Greedsize / 6);
br->GetBackground()->SetVisibility(true);
br->SetParent(bg);
br->SetAnchor((uint32_t)Ashita::FrameAnchor::TopLeft);
br->SetAnchorParent((uint32_t)Ashita::FrameAnchor::TopLeft);
br->SetPositionX(0);
br->SetPositionY(0);
br->SetVisibility(false);
prev = bg;
}
return true;
}
/**
* @brief Direct3D release call to allow this plugin to cleanup any Direct3D objects.
*/
void Greed::Direct3DRelease(void)
{
m_AshitaCore->GetFontManager()->Delete("GreedBase");
for (int i = 0; i < 18; i++)
{
char alias[32];
sprintf_s(alias, sizeof alias, "GreedBG%d", i);
m_AshitaCore->GetFontManager()->Delete(alias);
sprintf_s(alias, sizeof alias, "GreedFG%d", i);
m_AshitaCore->GetFontManager()->Delete(alias);
sprintf_s(alias, sizeof alias, "GreedTX%d", i);
m_AshitaCore->GetFontManager()->Delete(alias);
sprintf_s(alias, sizeof alias, "GreedIndicatorTopLeft%d", i);
m_AshitaCore->GetFontManager()->Delete(alias);
}
}
/**
* @brief Direct3D prerender call to allow this plugin to prepare for rendering.
*
* @note This will only be called if you returned true in Direct3DInitialize!
*/
void Greed::Direct3DPreRender(void)
{
}
/**
* @brief Direct3D render call to allow this plugin to render any custom things.
*
* @note This will only be called if you returned true in Direct3DInitialize!
*/
void Greed::Direct3DRender(void)
{
int party = 0;
for (int i = 0; i < 18; i++)
{
char alias[32];
sprintf_s(alias, sizeof alias, "GreedBG%d", i);
IFontObject* bg = m_AshitaCore->GetFontManager()->Get(alias);
sprintf_s(alias, sizeof alias, "GreedFG%d", i);
IFontObject* fg = m_AshitaCore->GetFontManager()->Get(alias);
sprintf_s(alias, sizeof alias, "GreedTX%d", i);
IFontObject* tx = m_AshitaCore->GetFontManager()->Get(alias);
sprintf_s(alias, sizeof alias, "GreedIndicatorTopLeft%d", i);
IFontObject* br = m_AshitaCore->GetFontManager()->Get(alias);
if (!m_AshitaCore->GetDataManager()->GetParty()->GetMemberActive(i))
{
bg->SetVisibility(false);
fg->SetVisibility(false);
tx->SetVisibility(false);
br->SetVisibility(false);
targIdMap[bg] = 0;
}
else
{
bg->SetVisibility(true);
fg->SetVisibility(true);
tx->SetVisibility(true);
uint8_t hpp = m_AshitaCore->GetDataManager()->GetParty()->GetMemberCurrentHPP(i);
uint8_t job = m_AshitaCore->GetDataManager()->GetParty()->GetMemberMainJob(i);
uint16_t index = m_AshitaCore->GetDataManager()->GetParty()->GetMemberTargetIndex(i);
if (config.jobColored && job <= (uint8_t)Ashita::FFXI::Enums::Jobs::RuneFencer)
{
bg->GetBackground()->SetColor(jobColors[job]);
fg->GetBackground()->SetColor(darken(jobColors[job]));
tx->SetColor(brighten(jobColors[job]));
}
fg->GetBackground()->SetHeight(bg->GetBackground()->GetHeight() * ((float)hpp / 100));
fg->SetAnchor((uint32_t)Ashita::FrameAnchor::BottomLeft);
std::string txString;
char rawString[16];
if (hpp > 90 || m_AshitaCore->GetDataManager()->GetParty()->GetMemberZone(i) != m_AshitaCore->GetDataManager()->GetParty()->GetMemberZone(0))
{
sprintf_s(rawString, sizeof rawString, "%.*s", (config.Greedsize / config.fontsize) + 1, m_AshitaCore->GetDataManager()->GetParty()->GetMemberName(i));
txString.append(rawString);
}
else if (hpp == 0)
{
txString.append("DEAD");
}
else
{
uint32_t hp = m_AshitaCore->GetDataManager()->GetParty()->GetMemberCurrentHP(i);
float hpguess = (int)(hp / ((float)hpp / 100)) - hp;
sprintf_s(rawString, sizeof rawString, "-%.*f", hpguess > 1000 ? 1 : 0, hpguess > 1000 ? hpguess / 1000 : hpguess);
txString.append(rawString);
}
tx->SetText(txString.c_str());
if (m_AshitaCore->GetDataManager()->GetParty()->GetMemberZone(i) != m_AshitaCore->GetDataManager()->GetParty()->GetMemberZone(0) ||
!(m_AshitaCore->GetDataManager()->GetEntity()->GetRenderFlags0(index) & 0x200) ||
m_AshitaCore->GetDataManager()->GetEntity()->GetDistance(index) > config.faderange)
{
bg->GetBackground()->SetColor((bg->GetBackground()->GetColor() & 0x00FFFFFF) | (0x10 << 24));
fg->GetBackground()->SetColor((fg->GetBackground()->GetColor() & 0x00FFFFFF) | (0x40 << 24));
tx->SetColor((tx->GetColor() & 0x00FFFFFF) | (0x40 << 24));
}
else
{
bg->GetBackground()->SetColor((bg->GetBackground()->GetColor() & 0x00FFFFFF) | (0xFF << 24));
fg->GetBackground()->SetColor((fg->GetBackground()->GetColor() & 0x00FFFFFF) | (0xFF << 24));
tx->SetColor((tx->GetColor() & 0x00FFFFFF) | (0xFF << 24));
}
if (m_AshitaCore->GetDataManager()->GetTarget()->GetTargetIndex() == index &&
m_AshitaCore->GetDataManager()->GetParty()->GetMemberZone(i) == m_AshitaCore->GetDataManager()->GetParty()->GetMemberZone(0))
{
br->SetVisibility(true);
}
else
{
br->SetVisibility(false);
}
targIdMap[bg] = m_AshitaCore->GetDataManager()->GetEntity()->GetServerId(index);
party |= (i / 6);
}
}
IFontObject* base = m_AshitaCore->GetFontManager()->Get("GreedBase");
int maxmem = std::max(m_AshitaCore->GetDataManager()->GetParty()->GetAllianceParty0MemberCount(), std::max(m_AshitaCore->GetDataManager()->GetParty()->GetAllianceParty1MemberCount(),
m_AshitaCore->GetDataManager()->GetParty()->GetAllianceParty2MemberCount()));
base->GetBackground()->SetWidth(config.spacing * 2 + maxmem * config.Greedsize + (maxmem - 1) * config.padding);
base->GetBackground()->SetHeight(config.Greedsize + config.spacing * 2 + (party & 1 ? config.Greedsize + config.padding : 0) +
(party & 2 ? config.Greedsize + config.padding : 0));
base->SetAnchor((uint32_t)config.anchor);
}
void Greed::LoadSettings()
{
config.faderange = FADERANGE;
config.fontsize = FONTSIZE;
config.Greedsize = GreedSIZE;
config.padding = PADDING;
config.spacing = SPACING;
config.anchor = Ashita::FrameAnchor::BottomRight;
config.x = -132;
config.y = -16;
config.rf = 0x50;
config.gf = 0x28;
config.bf = 0x00;
config.rb = 0xFF;
config.gb = 0x80;
config.bb = 0x00;
config.jobColored = true;
char szConfigPath[MAX_PATH] = { 0 };
sprintf_s(szConfigPath, MAX_PATH, "%sConfig\\%s.xml", m_AshitaCore->GetAshitaInstallPathA(), g_PluginInfo->Name);
try
{
xmlFile = new rapidxml::file<>(szConfigPath);
settings.parse<0>(xmlFile->data());
}
catch (std::exception& e)
{
m_AshitaCore->GetChatManager()->Writef("Greed: Could not load settings: %s", e.what());
m_AshitaCore->GetChatManager()->Write("Greed: If this is your first time running Greed, you'll need to make a profile in Config/Greed.xml (use the profile in Docs for reference)");
return;
}
auto node = settings.first_node("settings");
if (node)
{
auto setNode = node->first_node("faderange");
if (setNode)
config.faderange = pow(atof(setNode->value()),2);
setNode = node->first_node("fontsize");
if (setNode)
config.fontsize = atoi(setNode->value());
setNode = node->first_node("Greedsize");
if (setNode)
config.Greedsize = atoi(setNode->value());
setNode = node->first_node("padding");
if (setNode)
config.padding = atoi(setNode->value());
setNode = node->first_node("spacing");
if (setNode)
config.spacing = atoi(setNode->value());
setNode = node->first_node("anchor");
if (setNode)
config.anchor = static_cast<Ashita::FrameAnchor>(atoi(setNode->value()));
setNode = node->first_node("xpos");
if (setNode)
config.x = atoi(setNode->value());
setNode = node->first_node("ypos");
if (setNode)
config.y = atoi(setNode->value());
setNode = node->first_node("fgred");
if (setNode)
config.rf = atoi(setNode->value());
setNode = node->first_node("fggreen");
if (setNode)
config.gf = atoi(setNode->value());
setNode = node->first_node("fgblue");
if (setNode)
config.bf = atoi(setNode->value());
setNode = node->first_node("bgred");
if (setNode)
config.rb = atoi(setNode->value());
setNode = node->first_node("bggreen");
if (setNode)
config.gb = atoi(setNode->value());
setNode = node->first_node("bgblue");
if (setNode)
config.bb = atoi(setNode->value());
setNode = node->first_node("jobcolored");
if (setNode)
config.jobColored = strncmp(setNode->value(),"true",setNode->value_size()) ? false : true;
}
}
/**
* @brief Gets the interface version this plugin was compiled with.
*
* @note This is a required export, your plugin must implement this!
*/
__declspec(dllexport) double __stdcall GetInterfaceVersion(void)
{
return ASHITA_INTERFACE_VERSION;
}
/**
* @brief Gets the plugin data for this plugin.
*
* @note This is a required export, your plugin must implement this!
*/
__declspec(dllexport) void __stdcall CreatePluginInfo(plugininfo_t* lpBuffer)
{
g_PluginInfo = lpBuffer;
strcpy_s(g_PluginInfo->Name, sizeof(g_PluginInfo->Name), "Greed");
strcpy_s(g_PluginInfo->Author, sizeof(g_PluginInfo->Author), "kjLotus");
g_PluginInfo->InterfaceVersion = ASHITA_INTERFACE_VERSION;
g_PluginInfo->PluginVersion = 1.00f;
g_PluginInfo->Priority = 0;
}
/**
* @brief Creates an instance of this plugin object.
*
* @note This is a required export, your plugin must implement this!
*/
__declspec(dllexport) IPlugin* __stdcall CreatePlugin(void)
{
return (IPlugin*)new Greed();
}
void Greed::onClick(int type, IFontObject* font, float xPos, float yPos)
{
if (xmlFile)
{
std::string job = jobs[m_AshitaCore->GetDataManager()->GetPlayer()->GetMainJob()];
std::transform(job.begin(), job.end(), job.begin(), ::tolower);
auto node = settings.first_node(job.c_str());
uint32_t targid;
try
{
targid = targIdMap.at(font);
}
catch (const std::out_of_range& e)
{
return;
}
if (node)
{
std::string click;
if (type == (int)Ashita::MouseInput::LeftClick)
click.append("lclick");
else if (type == (int)Ashita::MouseInput::RightClick)
click.append("rclick");
else if (type == (int)Ashita::MouseInput::MiddleClick)
click.append("mclick");
else if (type == (int)Ashita::MouseInput::X1Click)
click.append("button4");
else if (type == (int)Ashita::MouseInput::X2Click)
click.append("button5");
else
return;
for (auto clickNode = node->first_node(click.c_str()); clickNode; clickNode = clickNode->next_sibling(click.c_str()))
{
uint8_t modifiers = (GetAsyncKeyState(VK_CONTROL) & 0x8000 ? 1 : 0);
modifiers |= (GetAsyncKeyState(VK_MENU) & 0x8000 ? 2 : 0);
uint8_t foundModifiers = 0;
auto attr = clickNode->first_attribute("modifier");
for (auto attr = clickNode->first_attribute("modifier"); attr; attr = attr->next_attribute("modifier"))
{
if (strcmp(attr->value(), "ctrl") == 0)
foundModifiers |= 1;
else if (strcmp(attr->value(), "alt") == 0)
foundModifiers |= 2;
}
if (modifiers == foundModifiers)
{
std::string action = clickNode->value();
char cmd[64];
sprintf_s(cmd, sizeof cmd, "%s %d", action.c_str(), targid);
m_AshitaCore->GetChatManager()->QueueCommand(cmd, (int32_t)Ashita::CommandInputType::Menu);
return;
}
}
}
else
{
//no config for this job, default left click: target
if (type == 0 && !(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
{
char cmd[64];
sprintf_s(cmd, sizeof cmd, "/target %d", targid);
m_AshitaCore->GetChatManager()->QueueCommand(cmd, (int32_t)Ashita::CommandInputType::Menu);
}
}
}
}

2596
Greed/rapidxml/rapidxml.hpp

File diff suppressed because it is too large Load Diff

174
Greed/rapidxml/rapidxml_iterators.hpp

@ -0,0 +1,174 @@ @@ -0,0 +1,174 @@
#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
#define RAPIDXML_ITERATORS_HPP_INCLUDED
// Copyright (C) 2006, 2009 Marcin Kalicinski
// Version 1.13
// Revision $DateTime: 2009/05/13 01:46:17 $
//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
#include "rapidxml.hpp"
namespace rapidxml
{
//! Iterator of child nodes of xml_node
template<class Ch>
class node_iterator
{
public:
typedef typename xml_node<Ch> value_type;
typedef typename xml_node<Ch> &reference;
typedef typename xml_node<Ch> *pointer;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
node_iterator()
: m_node(0)
{
}
node_iterator(xml_node<Ch> *node)
: m_node(node->first_node())
{
}
reference operator *() const
{
assert(m_node);
return *m_node;
}
pointer operator->() const
{
assert(m_node);
return m_node;
}
node_iterator& operator++()
{
assert(m_node);
m_node = m_node->next_sibling();
return *this;
}
node_iterator operator++(int)
{
node_iterator tmp = *this;
++this;
return tmp;
}
node_iterator& operator--()
{
assert(m_node && m_node->previous_sibling());
m_node = m_node->previous_sibling();
return *this;
}
node_iterator operator--(int)
{
node_iterator tmp = *this;
++this;
return tmp;
}
bool operator ==(const node_iterator<Ch> &rhs)
{
return m_node == rhs.m_node;
}
bool operator !=(const node_iterator<Ch> &rhs)
{
return m_node != rhs.m_node;
}
private:
xml_node<Ch> *m_node;
};
//! Iterator of child attributes of xml_node
template<class Ch>
class attribute_iterator
{
public:
typedef typename xml_attribute<Ch> value_type;
typedef typename xml_attribute<Ch> &reference;
typedef typename xml_attribute<Ch> *pointer;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
attribute_iterator()
: m_attribute(0)
{
}
attribute_iterator(xml_node<Ch> *node)
: m_attribute(node->first_attribute())
{
}
reference operator *() const
{
assert(m_attribute);
return *m_attribute;
}
pointer operator->() const
{
assert(m_attribute);
return m_attribute;
}
attribute_iterator& operator++()
{
assert(m_attribute);
m_attribute = m_attribute->next_attribute();
return *this;
}
attribute_iterator operator++(int)
{
attribute_iterator tmp = *this;
++this;
return tmp;
}
attribute_iterator& operator--()
{
assert(m_attribute && m_attribute->previous_attribute());
m_attribute = m_attribute->previous_attribute();
return *this;
}
attribute_iterator operator--(int)
{
attribute_iterator tmp = *this;
++this;
return tmp;
}
bool operator ==(const attribute_iterator<Ch> &rhs)
{
return m_attribute == rhs.m_attribute;
}
bool operator !=(const attribute_iterator<Ch> &rhs)
{
return m_attribute != rhs.m_attribute;
}
private:
xml_attribute<Ch> *m_attribute;
};
}
#endif

421
Greed/rapidxml/rapidxml_print.hpp

@ -0,0 +1,421 @@ @@ -0,0 +1,421 @@
#ifndef RAPIDXML_PRINT_HPP_INCLUDED
#define RAPIDXML_PRINT_HPP_INCLUDED
// Copyright (C) 2006, 2009 Marcin Kalicinski
// Version 1.13
// Revision $DateTime: 2009/05/13 01:46:17 $
//! \file rapidxml_print.hpp This file contains rapidxml printer implementation
#include "rapidxml.hpp"
// Only include streams if not disabled
#ifndef RAPIDXML_NO_STREAMS
#include <ostream>
#include <iterator>
#endif
namespace rapidxml
{
///////////////////////////////////////////////////////////////////////
// Printing flags
const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
///////////////////////////////////////////////////////////////////////
// Internal
//! \cond internal
namespace internal
{
///////////////////////////////////////////////////////////////////////////
// Internal character operations
// Copy characters from given range to given output iterator
template<class OutIt, class Ch>
inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out)
{
while (begin != end)
*out++ = *begin++;
return out;
}
// Copy characters from given range to given output iterator and expand
// characters into references (&lt; &gt; &apos; &quot; &amp;)
template<class OutIt, class Ch>
inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out)
{
while (begin != end)
{
if (*begin == noexpand)
{
*out++ = *begin; // No expansion, copy character
}
else
{
switch (*begin)
{
case Ch('<'):
*out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';');
break;
case Ch('>'):
*out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';');
break;
case Ch('\''):
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';');
break;
case Ch('"'):
*out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';');
break;
case Ch('&'):
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';');
break;
default:
*out++ = *begin; // No expansion, copy character
}
}
++begin; // Step to next character
}
return out;
}
// Fill given output iterator with repetitions of the same character
template<class OutIt, class Ch>
inline OutIt fill_chars(OutIt out, int n, Ch ch)
{
for (int i = 0; i < n; ++i)
*out++ = ch;
return out;
}
// Find character
template<class Ch, Ch ch>
inline bool find_char(const Ch *begin, const Ch *end)
{
while (begin != end)
if (*begin++ == ch)
return true;
return false;
}
///////////////////////////////////////////////////////////////////////////
// Internal printing operations
// Print node
template<class OutIt, class Ch>
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
// Print proper node type
switch (node->type())
{
// Document
case node_document:
out = print_children(out, node, flags, indent);
break;
// Element
case node_element:
out = print_element_node(out, node, flags, indent);
break;
// Data
case node_data:
out = print_data_node(out, node, flags, indent);
break;
// CDATA
case node_cdata:
out = print_cdata_node(out, node, flags, indent);
break;
// Declaration
case node_declaration:
out = print_declaration_node(out, node, flags, indent);
break;
// Comment
case node_comment:
out = print_comment_node(out, node, flags, indent);
break;
// Doctype
case node_doctype:
out = print_doctype_node(out, node, flags, indent);
break;
// Pi
case node_pi:
out = print_pi_node(out, node, flags, indent);
break;
// Unknown
default:
assert(0);
break;
}
// If indenting not disabled, add line break after node
if (!(flags & print_no_indenting))
*out = Ch('\n'), ++out;
// Return modified iterator
return out;
}
// Print children of the node
template<class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling())
out = print_node(out, child, flags, indent);
return out;
}
// Print attributes of the node
template<class OutIt, class Ch>
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags)
{
for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute())
{
if (attribute->name() && attribute->value())
{
// Print attribute name
*out = Ch(' '), ++out;
out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
*out = Ch('='), ++out;
// Print attribute value using appropriate quote type
if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size()))
{
*out = Ch('\''), ++out;
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out);
*out = Ch('\''), ++out;
}
else
{
*out = Ch('"'), ++out;
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out);
*out = Ch('"'), ++out;
}
}
}
return out;
}
// Print data node
template<class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
assert(node->type() == node_data);
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
return out;
}
// Print data node
template<class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
assert(node->type() == node_cdata);
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
*out = Ch('<'); ++out;
*out = Ch('!'); ++out;
*out = Ch('['); ++out;
*out = Ch('C'); ++out;
*out = Ch('D'); ++out;
*out = Ch('A'); ++out;
*out = Ch('T'); ++out;
*out = Ch('A'); ++out;
*out = Ch('['); ++out;
out = copy_chars(node->value(), node->value() + node->value_size(), out);
*out = Ch(']'); ++out;
*out = Ch(']'); ++out;
*out = Ch('>'); ++out;
return out;
}
// Print element node
template<class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
assert(node->type() == node_element);
// Print element name and attributes, if any
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
*out = Ch('<'), ++out;
out = copy_chars(node->name(), node->name() + node->name_size(), out);
out = print_attributes(out, node, flags);
// If node is childless
if (node->value_size() == 0 && !node->first_node())
{
// Print childless node tag ending
*out = Ch('/'), ++out;
*out = Ch('>'), ++out;
}
else
{
// Print normal node tag ending
*out = Ch('>'), ++out;
// Test if node contains a single data node only (and no other nodes)
xml_node<Ch> *child = node->first_node();
if (!child)
{
// If node has no children, only print its value without indenting
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
}
else if (child->next_sibling() == 0 && child->type() == node_data)
{
// If node has a sole data child, only print its value without indenting
out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out);
}
else
{
// Print all children with full indenting
if (!(flags & print_no_indenting))
*out = Ch('\n'), ++out;
out = print_children(out, node, flags, indent + 1);
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
}
// Print node end
*out = Ch('<'), ++out;
*out = Ch('/'), ++out;
out = copy_chars(node->name(), node->name() + node->name_size(), out);
*out = Ch('>'), ++out;
}
return out;
}
// Print declaration node
template<class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
// Print declaration start
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
*out = Ch('<'), ++out;
*out = Ch('?'), ++out;
*out = Ch('x'), ++out;
*out = Ch('m'), ++out;
*out = Ch('l'), ++out;
// Print attributes
out = print_attributes(out, node, flags);
// Print declaration end
*out = Ch('?'), ++out;
*out = Ch('>'), ++out;
return out;
}
// Print comment node
template<class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
assert(node->type() == node_comment);
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
*out = Ch('<'), ++out;
*out = Ch('!'), ++out;
*out = Ch('-'), ++out;
*out = Ch('-'), ++out;
out = copy_chars(node->value(), node->value() + node->value_size(), out);
*out = Ch('-'), ++out;
*out = Ch('-'), ++out;
*out = Ch('>'), ++out;
return out;
}
// Print doctype node
template<class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
assert(node->type() == node_doctype);
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
*out = Ch('<'), ++out;
*out = Ch('!'), ++out;
*out = Ch('D'), ++out;
*out = Ch('O'), ++out;
*out = Ch('C'), ++out;
*out = Ch('T'), ++out;
*out = Ch('Y'), ++out;
*out = Ch('P'), ++out;
*out = Ch('E'), ++out;
*out = Ch(' '), ++out;
out = copy_chars(node->value(), node->value() + node->value_size(), out);
*out = Ch('>'), ++out;
return out;
}
// Print pi node
template<class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
{
assert(node->type() == node_pi);
if (!(flags & print_no_indenting))
out = fill_chars(out, indent, Ch('\t'));
*out = Ch('<'), ++out;
*out = Ch('?'), ++out;
out = copy_chars(node->name(), node->name() + node->name_size(), out);
*out = Ch(' '), ++out;
out = copy_chars(node->value(), node->value() + node->value_size(), out);
*out = Ch('?'), ++out;
*out = Ch('>'), ++out;
return out;
}
}
//! \endcond
///////////////////////////////////////////////////////////////////////////
// Printing
//! Prints XML to given output iterator.
//! \param out Output iterator to print to.
//! \param node Node to be printed. Pass xml_document to print entire document.
//! \param flags Flags controlling how XML is printed.
//! \return Output iterator pointing to position immediately after last character of printed text.
template<class OutIt, class Ch>
inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0)
{
return internal::print_node(out, &node, flags, 0);
}
#ifndef RAPIDXML_NO_STREAMS
//! Prints XML to given output stream.
//! \param out Output stream to print to.
//! \param node Node to be printed. Pass xml_document to print entire document.
//! \param flags Flags controlling how XML is printed.
//! \return Output stream.
template<class Ch>
inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0)
{
print(std::ostream_iterator<Ch>(out), node, flags);
return out;
}
//! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.
//! \param out Output stream to print to.
//! \param node Node to be printed.
//! \return Output stream.
template<class Ch>
inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out, const xml_node<Ch> &node)
{
return print(out, node);
}
#endif
}
#endif

122
Greed/rapidxml/rapidxml_utils.hpp

@ -0,0 +1,122 @@ @@ -0,0 +1,122 @@
#ifndef RAPIDXML_UTILS_HPP_INCLUDED
#define RAPIDXML_UTILS_HPP_INCLUDED
// Copyright (C) 2006, 2009 Marcin Kalicinski
// Version 1.13
// Revision $DateTime: 2009/05/13 01:46:17 $
//! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful
//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
#include "rapidxml.hpp"
#include <vector>
#include <string>
#include <fstream>
#include <stdexcept>
namespace rapidxml
{
//! Represents data loaded from a file
template<class Ch = char>
class file
{
public:
//! Loads file into the memory. Data will be automatically destroyed by the destructor.
//! \param filename Filename to load.
file(const char *filename)
{
using namespace std;
// Open stream
basic_ifstream<Ch> stream(filename, ios::binary);
if (!stream)
throw runtime_error(string("cannot open file ") + filename);
stream.unsetf(ios::skipws);
// Determine stream size
stream.seekg(0, ios::end);
size_t size = stream.tellg();
stream.seekg(0);
// Load data and add terminating 0
m_data.resize(size + 1);
stream.read(&m_data.front(), static_cast<streamsize>(size));
m_data[size] = 0;
}
//! Loads file into the memory. Data will be automatically destroyed by the destructor
//! \param stream Stream to load from
file(std::basic_istream<Ch> &stream)
{
using namespace std;
// Load data and add terminating 0
stream.unsetf(ios::skipws);
m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
if (stream.fail() || stream.bad())
throw runtime_error("error reading stream");
m_data.push_back(0);
}
//! Gets file data.
//! \return Pointer to data of file.
Ch *data()
{
return &m_data.front();
}
//! Gets file data.
//! \return Pointer to data of file.
const Ch *data() const
{
return &m_data.front();
}
//! Gets file data size.
//! \return Size of file data, in characters.
std::size_t size() const
{
return m_data.size();
}
private:
std::vector<Ch> m_data; // File data
};
//! Counts children of node. Time complexity is O(n).
//! \return Number of children of node
template<class Ch>
inline std::size_t count_children(xml_node<Ch> *node)
{
xml_node<Ch> *child = node->first_node();
std::size_t count = 0;
while (child)
{
++count;
child = child->next_sibling();
}
return count;
}
//! Counts attributes of node. Time complexity is O(n).
//! \return Number of attributes of node
template<class Ch>
inline std::size_t count_attributes(xml_node<Ch> *node)
{
xml_attribute<Ch> *attr = node->first_attribute();
std::size_t count = 0;
while (attr)
{
++count;
attr = attr->next_attribute();
}
return count;
}
}
#endif

1
README.md

@ -0,0 +1 @@ @@ -0,0 +1 @@
# Greed
Loading…
Cancel
Save