├── .gitignore
├── DEVELOPMENT.md
├── README.md
├── common
├── IArchive.cpp
├── IArchive.h
├── IBufferStream.cpp
├── IBufferStream.h
├── IConsole.cpp
├── IConsole.h
├── ICriticalSection.h
├── IDataStream.cpp
├── IDataStream.h
├── IDatabase.cpp
├── IDatabase.h
├── IDatabase.inc
├── IDebugLog.cpp
├── IDebugLog.h
├── IDirectoryIterator.cpp
├── IDirectoryIterator.h
├── IDynamicCreate.cpp
├── IDynamicCreate.h
├── IErrors.cpp
├── IErrors.h
├── IEvent.cpp
├── IEvent.h
├── IFIFO.cpp
├── IFIFO.h
├── IFileStream.cpp
├── IFileStream.h
├── IInterlockedLong.cpp
├── IInterlockedLong.h
├── ILinkedList.h
├── IMemPool.cpp
├── IMemPool.h
├── IMutex.cpp
├── IMutex.h
├── IObjectPool.cpp
├── IObjectPool.h
├── IPipeClient.cpp
├── IPipeClient.h
├── IPipeServer.cpp
├── IPipeServer.h
├── IPrefix.cpp
├── IPrefix.h
├── IRangeMap.cpp
├── IRangeMap.h
├── IReadWriteLock.cpp
├── IReadWriteLock.h
├── ISegmentStream.cpp
├── ISegmentStream.h
├── ISingleton.cpp
├── ISingleton.h
├── ITextParser.cpp
├── ITextParser.h
├── IThread.cpp
├── IThread.h
├── ITimer.cpp
├── ITimer.h
├── ITypes.cpp
├── ITypes.h
├── common.vcproj
├── common_license.txt
├── common_vc9.vcproj
├── common_vc9.vcxproj
└── common_vc9.vcxproj.filters
├── nvse
├── Algohol
│ ├── algMath.cpp
│ ├── algMath.h
│ ├── algTypes.h
│ ├── license.txt
│ ├── paramTypes.cpp
│ └── paramTypes.h
├── loader_common
│ ├── Error.cpp
│ ├── Error.h
│ ├── IdentifyEXE.cpp
│ ├── IdentifyEXE.h
│ ├── PluginChecker.cpp
│ ├── PluginChecker.h
│ ├── loader_common.vcproj
│ └── loader_common.vcxproj
├── nvse.sln
├── nvse
│ ├── ArrayVar.cpp
│ ├── ArrayVar.h
│ ├── ArrayVarElementContainer.cpp
│ ├── CachedScripts.cpp
│ ├── CachedScripts.h
│ ├── CommandTable.cpp
│ ├── CommandTable.h
│ ├── Commands_Array.cpp
│ ├── Commands_Array.h
│ ├── Commands_Console.cpp
│ ├── Commands_Console.h
│ ├── Commands_Factions.cpp
│ ├── Commands_Factions.h
│ ├── Commands_Game.cpp
│ ├── Commands_Game.h
│ ├── Commands_Input.cpp
│ ├── Commands_Input.h
│ ├── Commands_Inventory.cpp
│ ├── Commands_Inventory.h
│ ├── Commands_InventoryRef.cpp
│ ├── Commands_InventoryRef.h
│ ├── Commands_List.cpp
│ ├── Commands_List.h
│ ├── Commands_Math.cpp
│ ├── Commands_Math.h
│ ├── Commands_Misc.cpp
│ ├── Commands_Misc.h
│ ├── Commands_MiscRef.cpp
│ ├── Commands_MiscRef.h
│ ├── Commands_NetImmerse.cpp
│ ├── Commands_NetImmerse.h
│ ├── Commands_Packages.cpp
│ ├── Commands_Packages.h
│ ├── Commands_Quest.cpp
│ ├── Commands_Quest.h
│ ├── Commands_Script.cpp
│ ├── Commands_Script.h
│ ├── Commands_Scripting.cpp
│ ├── Commands_Scripting.h
│ ├── Commands_String.cpp
│ ├── Commands_String.h
│ ├── Commands_UI.cpp
│ ├── Commands_UI.h
│ ├── Core_Serialization.cpp
│ ├── Core_Serialization.h
│ ├── DebuggerVisualizations.natvis
│ ├── EventManager.cpp
│ ├── EventManager.h
│ ├── EventParams.h
│ ├── FastStack.h
│ ├── FormExtraData.cpp
│ ├── FormExtraData.h
│ ├── FunctionScripts.cpp
│ ├── FunctionScripts.h
│ ├── GameAPI.cpp
│ ├── GameAPI.h
│ ├── GameBSExtraData.cpp
│ ├── GameBSExtraData.h
│ ├── GameData.cpp
│ ├── GameData.h
│ ├── GameEffects.h
│ ├── GameExtraData.cpp
│ ├── GameExtraData.h
│ ├── GameForms.cpp
│ ├── GameForms.h
│ ├── GameOSDepend.cpp
│ ├── GameOSDepend.h
│ ├── GameObjects.cpp
│ ├── GameObjects.h
│ ├── GameProcess.cpp
│ ├── GameProcess.h
│ ├── GameRTTI.cpp
│ ├── GameRTTI.h
│ ├── GameRTTI_1_4_0_525.inc
│ ├── GameRTTI_1_4_0_525ng.inc
│ ├── GameRTTI_EDITOR.inc
│ ├── GameScript.cpp
│ ├── GameScript.h
│ ├── GameSettings.cpp
│ ├── GameSettings.h
│ ├── GameTasks.cpp
│ ├── GameTasks.h
│ ├── GameTiles.cpp
│ ├── GameTiles.h
│ ├── GameTypes.cpp
│ ├── GameTypes.h
│ ├── GameUI.cpp
│ ├── GameUI.h
│ ├── Hooks_Animation.cpp
│ ├── Hooks_Animation.h
│ ├── Hooks_CreatedObject.cpp
│ ├── Hooks_CreatedObject.h
│ ├── Hooks_Dialog.cpp
│ ├── Hooks_Dialog.h
│ ├── Hooks_DirectInput8Create.cpp
│ ├── Hooks_DirectInput8Create.h
│ ├── Hooks_Editor.cpp
│ ├── Hooks_Editor.h
│ ├── Hooks_Gameplay.cpp
│ ├── Hooks_Gameplay.h
│ ├── Hooks_Logging.cpp
│ ├── Hooks_Logging.h
│ ├── Hooks_Memory.cpp
│ ├── Hooks_Memory.h
│ ├── Hooks_Other.cpp
│ ├── Hooks_Other.h
│ ├── Hooks_SaveLoad.cpp
│ ├── Hooks_SaveLoad.h
│ ├── Hooks_Script.cpp
│ ├── Hooks_Script.h
│ ├── InventoryInfo.cpp
│ ├── InventoryInfo.h
│ ├── InventoryRef.cpp
│ ├── InventoryRef.h
│ ├── InventoryReference.cpp
│ ├── InventoryReference.h
│ ├── LambdaManager.cpp
│ ├── LambdaManager.h
│ ├── Loops.cpp
│ ├── Loops.h
│ ├── MemoizedMap.h
│ ├── MemoryPool.cpp
│ ├── MemoryPool.h
│ ├── MemoryTracker.h
│ ├── NVSEAst.h
│ ├── NVSECompiler.cpp
│ ├── NVSECompiler.h
│ ├── NVSECompilerUtils.cpp
│ ├── NVSECompilerUtils.h
│ ├── NVSELexer.cpp
│ ├── NVSELexer.h
│ ├── NVSEParser.cpp
│ ├── NVSEParser.h
│ ├── NVSEScope.h
│ ├── NVSETreePrinter.cpp
│ ├── NVSETreePrinter.h
│ ├── NVSETypeChecker.cpp
│ ├── NVSETypeChecker.h
│ ├── NVSEVisitor.h
│ ├── NiNodes.cpp
│ ├── NiNodes.h
│ ├── NiObjects.cpp
│ ├── NiObjects.h
│ ├── NiPoint.h
│ ├── NiTypes.cpp
│ ├── NiTypes.h
│ ├── OverloadsGlobal.cpp
│ ├── ParamInfos.h
│ ├── PluginAPI.h
│ ├── PluginManager.cpp
│ ├── PluginManager.h
│ ├── SafeWrite.cpp
│ ├── SafeWrite.h
│ ├── ScriptAnalyzer.cpp
│ ├── ScriptAnalyzer.h
│ ├── ScriptTokenCache.cpp
│ ├── ScriptTokenCache.h
│ ├── ScriptTokens.cpp
│ ├── ScriptTokens.h
│ ├── ScriptUtils.cpp
│ ├── ScriptUtils.h
│ ├── Serialization.cpp
│ ├── Serialization.h
│ ├── SmallObjectsAllocator.h
│ ├── StackVariables.cpp
│ ├── StackVariables.h
│ ├── StackVector.h
│ ├── StringVar.cpp
│ ├── StringVar.h
│ ├── ThreadLocal.cpp
│ ├── ThreadLocal.h
│ ├── UnitTests.cpp
│ ├── UnitTests.h
│ ├── Utilities.cpp
│ ├── Utilities.h
│ ├── VarMap.h
│ ├── commands_Algohol.cpp
│ ├── commands_Algohol.h
│ ├── containers.cpp
│ ├── containers.h
│ ├── exports.def
│ ├── nvse.cpp
│ ├── nvse.vcproj
│ ├── nvse.vcxproj
│ ├── nvse.vcxproj.filters
│ ├── nvse_version.h
│ ├── nvse_version.rc
│ ├── prefix.h
│ ├── printf.cpp
│ ├── printf.h
│ ├── rewrites.h
│ ├── unit_tests
│ │ ├── new_compiler
│ │ │ ├── binary_operations.txt
│ │ │ ├── call_test.txt
│ │ │ ├── comments.txt
│ │ │ ├── disabled
│ │ │ │ └── in_operator_syntax.txt
│ │ │ ├── for_loops.txt
│ │ │ ├── foreachalt.txt
│ │ │ ├── misc.txt
│ │ │ ├── stack_vars.txt
│ │ │ ├── ternary_operations.txt
│ │ │ ├── udfs
│ │ │ │ └── TestUDF.txt
│ │ │ └── unary_operations.txt
│ │ └── old_compiler
│ │ │ ├── CallAfterFrames.txt
│ │ │ ├── TestExpr.txt
│ │ │ ├── array_functions.txt
│ │ │ ├── conversions_between_num_and_string.txt
│ │ │ ├── event_handler_functions.txt
│ │ │ ├── event_handler_priority_system.txt
│ │ │ ├── let_macro.txt
│ │ │ ├── multi_arg_command_trailing_boundary.txt
│ │ │ ├── multiple_variable_declarations_macro.txt
│ │ │ ├── short_and_long_param_types_in_UDF.txt
│ │ │ ├── strings_and_parentheses.txt
│ │ │ └── udf_functions.txt
│ ├── utility.cpp
│ └── utility.h
├── nvse_loader
│ ├── Inject.cpp
│ ├── Inject.h
│ ├── Options.cpp
│ ├── Options.h
│ ├── main.cpp
│ ├── nvse_loader.ico
│ ├── nvse_loader.vcproj
│ ├── nvse_loader.vcxproj
│ └── resources.rc
└── steam_loader
│ ├── PluginPreload.h
│ ├── main.cpp
│ ├── steam_loader.vcproj
│ ├── steam_loader.vcxproj
│ └── steam_loader.vcxproj.filters
└── nvse_plugin_example
├── dllmain.c
├── exports.def
├── fn_intro_to_script_functions.h
├── fn_typed_functions.h
├── main.cpp
├── nvse_plugin_example.sln
├── nvse_plugin_example.vcproj
├── nvse_plugin_example.vcxproj
└── nvse_plugin_example.vcxproj.filters
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | **New Vegas Script Extender** (xNVSE) expands the engine and scripting capabilities of Fallout New Vegas.
9 |
10 | ## Download
11 |
12 | [Download the latest NVSE](https://github.com/xNVSE/NVSE/releases)
13 |
14 | -Changelogs and all releases are provided in the [releases section](https://github.com/xNVSE/NVSE/releases). Do not try to install using the Code .zip source code button GitHub shows.
15 |
16 | Releases are also available on [Nexus Mods](https://www.nexusmods.com/newvegas/mods/67883) and [Mod Pub](https://mod.pub/falloutnv/41-new-vegas-script-extender-nvse-xnvse).
17 |
18 | ## Installation
19 |
20 | 1. Copy the .dll and .exe files to your Fallout NV directory. For Steam this is usually in your Program Files folder under *Steam\\steamapps\\common\\Fallout New Vegas\\*. If you see files named FalloutNV.exe and FalloutNVLauncher.exe, this is the correct folder. **Do not copy these files to the Data folder or install it with MO2 as with a normal mod.**
21 |
22 | 2. Launch NV via running *nvse_loader.exe* or, if you have patched the game using [FNV 4GB Patcher](https://www.nexusmods.com/newvegas/mods/62552/), *FalloutNV.exe*. Enabling the Steam Community option (enabled by default) will allow you to launch the game via Steam's standard UI.
23 |
24 | xNVSE is compatible with the Steam and GOG versions of the game. German No Gore, Xbox Gamepass, and Bethesda.net versions are not supported. Epic Games Store users can use the [Epic Games Patcher](https://www.nexusmods.com/newvegas/mods/81281).
25 |
26 | ## Support
27 |
28 | For support, contact us in the [xNVSE Discord server](https://discord.gg/EebN93s). For bug reports and other problems, [create a new GitHub issue](https://github.com/NVSEx/NVSE/issues).
29 |
30 | If you experience a crash related to installing xNVSE, please try disabling all other mods to see if xNVSE is the culprit. If the problem persists, please include a crash log generated by a [Crash Logger](https://www.nexusmods.com/newvegas/mods/82540) inside your bug report.
31 |
32 | ## Description
33 |
34 | **New Vegas Script Extender** (NVSE) is a modder's resource that expands the scripting capabilities of Fallout: New Vegas. It does so without modifying the executable files on disk, so there are no permanent side effects.
35 |
36 |
37 | For documentation on how to write scripts utilizing NVSE, see [GECK Wiki](https://geckwiki.com/index.php?title=Main_Page).
38 |
39 | ## Making a Plugin, and/or Contributing
40 | See [DEVELOPMENT.md](https://github.com/xNVSE/NVSE/blob/master/DEVELOPMENT.md).
41 |
42 | ## Credits
43 |
44 | The original NVSE was created and maintained by *Ian Patterson*,
45 | *Stephen Abel*, *Paul Connelly*, and *Hugues LE PORS*
46 | (ianpatt, behippo, scruggsywuggsy the ferret, and hlp)
47 |
48 | xNVSE is developed by *korri123* (Kormákur), *jazzisparis*, and *Demorome*.
49 |
50 | xNVSE has contributions from *lStewieAl*, *c6* and *carxt*
51 |
--------------------------------------------------------------------------------
/common/IArchive.cpp:
--------------------------------------------------------------------------------
1 | #include "IArchive.h"
2 | #include "IErrors.h"
3 |
4 | #if ENABLE_IDYNAMICCREATE
5 |
6 | IDynamic * IArchive::iterator::Instantiate(void)
7 | {
8 | IDataSubStream subStream(owner->theStream, GetDataOffset(), GetDataLength());
9 |
10 | return IClassRegistry::Instantiate(GetTypeID(), &subStream);
11 | }
12 |
13 | void * IArchive::iterator::GetBuffer(UInt32 * outLength)
14 | {
15 | HeaderEntry * entry = GetData();
16 | UInt8 * buf = new UInt8[entry->dataLength];
17 |
18 | owner->theStream->SetOffset(entry->dataOffset);
19 | owner->theStream->ReadBuf(buf, entry->dataLength);
20 |
21 | if(outLength)
22 | *outLength = entry->dataLength;
23 |
24 | return buf;
25 | }
26 |
27 | void IArchive::iterator::NextOfType(UInt32 typeID)
28 | {
29 | idx++;
30 |
31 | while((GetData()->typeID != typeID) && (idx < owner->header.numEntries))
32 | idx++;
33 | }
34 |
35 | void IArchive::iterator::PrevOfType(UInt32 typeID)
36 | {
37 | idx--;
38 |
39 | while((GetData()->typeID != typeID) && (idx > 0))
40 | idx--;
41 | }
42 |
43 | IArchive::IArchive()
44 | :theStream(NULL), entries(NULL), nameTable(NULL)
45 | {
46 |
47 | }
48 |
49 | IArchive::IArchive(IDataStream * stream)
50 | :theStream(NULL), entries(NULL), nameTable(NULL)
51 | {
52 | AttachStream(stream);
53 | }
54 |
55 | IArchive::~IArchive()
56 | {
57 | Dispose();
58 | }
59 |
60 | void IArchive::AttachStream(IDataStream * inStream)
61 | {
62 | Dispose();
63 |
64 | theStream = inStream;
65 | }
66 |
67 | void IArchive::Dispose(void)
68 | {
69 | if(entries)
70 | {
71 | delete entries;
72 | entries = NULL;
73 | }
74 |
75 | if(nameTable)
76 | {
77 | delete nameTable;
78 | nameTable = NULL;
79 | }
80 | }
81 |
82 | void IArchive::ReadHeader(void)
83 | {
84 | ASSERT(theStream);
85 |
86 | theStream->Rewind();
87 |
88 | theStream->ReadBuf(&header, sizeof(FileHeader));
89 |
90 | entries = new HeaderEntry[header.numEntries];
91 | theStream->ReadBuf(entries, header.numEntries * sizeof(HeaderEntry));
92 |
93 | if(header.nameTableLength)
94 | {
95 | nameTable = new char[header.nameTableLength];
96 |
97 | theStream->SetOffset(header.nameTableOffset);
98 | theStream->ReadBuf(nameTable, header.nameTableLength);
99 | }
100 | }
101 |
102 | #endif
103 |
--------------------------------------------------------------------------------
/common/IArchive.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "common/IDataStream.h"
4 | #include "common/IDynamicCreate.h"
5 |
6 | #if ENABLE_IDYNAMICCREATE
7 |
8 | /**
9 | * An object archive
10 | *
11 | * This class implements reading and instantiating objects from an object archive.
12 | */
13 | class IArchive
14 | {
15 | public:
16 | class iterator;
17 | friend iterator;
18 |
19 | IArchive();
20 | IArchive(IDataStream * inStream);
21 | ~IArchive();
22 |
23 | void AttachStream(IDataStream * inStream);
24 | void Dispose(void);
25 |
26 | iterator begin(void) { return iterator(0, this); }
27 | iterator end(void) { return iterator(header.numEntries, this); }
28 |
29 | static const UInt32 kFileID = CHAR_CODE(0x00, 'A', 'R', 0x01);
30 | static const UInt32 kCurrentVersion = VERSION_CODE(1, 0, 0);
31 |
32 | private:
33 | struct FileHeader
34 | {
35 | UInt32 fileID; // IArchive::kFileID
36 | UInt32 version; // IArchive::kCurrentVersion
37 | UInt32 numEntries;
38 | UInt32 nameTableOffset;
39 | UInt32 nameTableLength;
40 | };
41 |
42 | struct HeaderEntry
43 | {
44 | UInt32 typeID;
45 | UInt32 subID;
46 | UInt32 dataOffset;
47 | UInt32 dataLength;
48 | UInt32 nameOffset;
49 | };
50 |
51 | void ReadHeader(void);
52 |
53 | IDataStream * theStream;
54 |
55 | FileHeader header;
56 | HeaderEntry * entries;
57 |
58 | char * nameTable;
59 |
60 | public:
61 | class iterator
62 | {
63 | public:
64 | iterator() { idx = 0; owner = NULL; }
65 | iterator(UInt32 inIdx, IArchive * inArchive) { idx = inIdx; owner = inArchive; }
66 | ~iterator() { }
67 |
68 | IDynamic * Instantiate(void);
69 |
70 | UInt32 GetTypeID(void) { return GetData()->typeID; }
71 | UInt32 GetSubID(void) { return GetData()->subID; }
72 | UInt32 GetDataLength(void) { return GetData()->dataLength; }
73 | char * GetName(void) { return &owner->nameTable[GetData()->nameOffset]; }
74 | void * GetBuffer(UInt32 * outLength);
75 |
76 | iterator & operator++() { Next(); return *this; }
77 | iterator & operator--() { Prev(); return *this; }
78 |
79 | void NextOfType(UInt32 typeID);
80 | void Next(void) { idx++; }
81 |
82 | void PrevOfType(UInt32 typeID);
83 | void Prev(void) { idx--; }
84 |
85 | private:
86 | HeaderEntry * GetData(void) { return &owner->entries[idx]; }
87 |
88 | UInt32 GetDataOffset(void) { return GetData()->dataOffset; }
89 |
90 | UInt32 idx;
91 | IArchive * owner;
92 | };
93 | };
94 |
95 | #endif
96 |
--------------------------------------------------------------------------------
/common/IBufferStream.cpp:
--------------------------------------------------------------------------------
1 | #include "IBufferStream.h"
2 |
3 | IBufferStream::IBufferStream()
4 | :streamBuf(NULL), flags(0)
5 | {
6 |
7 | }
8 |
9 | IBufferStream::IBufferStream(const IBufferStream & rhs)
10 | {
11 | // explicitly not supporting copy constructor for self-owned buffers
12 | ASSERT((flags & kFlag_OwnedBuf) == 0);
13 | }
14 |
15 | IBufferStream::IBufferStream(void * buf, UInt64 inLength)
16 | :streamBuf(NULL), flags(0)
17 | {
18 | SetBuffer(buf, inLength);
19 | }
20 |
21 | IBufferStream::~IBufferStream()
22 | {
23 | if(flags & kFlag_OwnedBuf)
24 | {
25 | delete [] streamBuf;
26 | }
27 | }
28 |
29 | IBufferStream & IBufferStream::operator=(IBufferStream & rhs)
30 | {
31 | // explicitly not supporting copying for self-owned buffers
32 | ASSERT((flags & kFlag_OwnedBuf) == 0);
33 |
34 | streamBuf = rhs.streamBuf;
35 | flags = rhs.flags;
36 |
37 | return *this;
38 | }
39 |
40 | void IBufferStream::SetBuffer(void * buf, UInt64 inLength)
41 | {
42 | streamBuf = (UInt8 *)buf;
43 | streamLength = inLength;
44 |
45 | Rewind();
46 | }
47 |
48 | void IBufferStream::ReadBuf(void * buf, UInt32 inLength)
49 | {
50 | memcpy(buf, &streamBuf[streamOffset], inLength);
51 | streamOffset += inLength;
52 | }
53 |
54 | void IBufferStream::WriteBuf(const void * buf, UInt32 inLength)
55 | {
56 | memcpy(&streamBuf[streamOffset], buf, inLength);
57 | streamOffset += inLength;
58 | }
59 |
--------------------------------------------------------------------------------
/common/IBufferStream.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "common/IDataStream.h"
4 |
5 | class IBufferStream : public IDataStream
6 | {
7 | public:
8 | IBufferStream();
9 | IBufferStream(const IBufferStream & rhs);
10 | IBufferStream(void * buf, UInt64 inLength);
11 | virtual ~IBufferStream();
12 |
13 | IBufferStream & operator=(IBufferStream & rhs);
14 |
15 | void SetBuffer(void * buf, UInt64 inLength);
16 | void * GetBuffer(void) { return streamBuf; }
17 |
18 | void OwnBuffer(void) { flags |= kFlag_OwnedBuf; }
19 | void DisownBuffer(void) { flags &= ~kFlag_OwnedBuf; }
20 |
21 | // read
22 | virtual void ReadBuf(void * buf, UInt32 inLength);
23 |
24 | // write
25 | virtual void WriteBuf(const void * buf, UInt32 inLength);
26 |
27 | protected:
28 | UInt8 * streamBuf;
29 | UInt32 flags;
30 |
31 | enum
32 | {
33 | kFlag_OwnedBuf = 1 << 0
34 | };
35 | };
36 |
--------------------------------------------------------------------------------
/common/IConsole.cpp:
--------------------------------------------------------------------------------
1 | #include "common/IConsole.h"
2 | #include
3 | #include
4 | #include
5 |
6 | IConsole::IConsole()
7 | {
8 | AllocConsole();
9 |
10 | SetConsoleTitle("Console");
11 |
12 | inputHandle = GetStdHandle(STD_INPUT_HANDLE);
13 | outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
14 |
15 | ASSERT_STR(inputHandle, "IConsole: couldn't get input handle");
16 | ASSERT_STR(outputHandle, "IConsole: couldn't get output handle");
17 |
18 | SetConsoleMode(inputHandle, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
19 | SetConsoleMode(outputHandle, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
20 | }
21 |
22 | IConsole::~IConsole()
23 | {
24 |
25 | }
26 |
27 | /**
28 | * Writes a string to the console
29 | */
30 | void IConsole::Write(char * buf)
31 | {
32 | UInt32 charsWritten;
33 |
34 | WriteConsole(outputHandle, buf, std::strlen(buf), &charsWritten, NULL);
35 | }
36 |
37 | /**
38 | * Writes a formatted string to the console
39 | *
40 | * You may specify a temp buffer to use for the formatted text, but if NULL
41 | * is used a local buffer will be provided.
42 | *
43 | * @param buf a temporary buffer, or NULL to use the internal buffer
44 | * @param fmt the format string
45 | */
46 | void IConsole::Write(char * buf, UInt32 bufLen, const char * fmt, ...)
47 | {
48 | static char tempBuf[4096];
49 |
50 | if(!buf)
51 | {
52 | buf = tempBuf;
53 | bufLen = sizeof(tempBuf);
54 | }
55 |
56 | va_list args;
57 |
58 | va_start(args, fmt);
59 | vsprintf_s(buf, bufLen, fmt, args);
60 | va_end(args);
61 |
62 | Write(buf);
63 | }
64 |
65 | /**
66 | * Reads a single character from the console
67 | */
68 | char IConsole::ReadChar(void)
69 | {
70 | char data;
71 | UInt32 charsRead;
72 |
73 | ReadConsole(inputHandle, &data, 1, &charsRead, NULL);
74 |
75 | return data;
76 | }
77 |
78 | /**
79 | * Reads a newline-terminated string from the console
80 | *
81 | * @param buf output buffer
82 | * @param len buffer size
83 | * @return number of characters read
84 | */
85 | UInt32 IConsole::ReadBuf(char * buf, UInt32 len)
86 | {
87 | UInt32 charsRead;
88 |
89 | buf[0] = 0;
90 |
91 | do
92 | {
93 | ReadConsole(inputHandle, buf, len, &charsRead, NULL);
94 | }
95 | while(!charsRead);
96 |
97 | int done = 0;
98 | for(UInt32 i = charsRead - 1; (i > 0) && !done; i--)
99 | {
100 | switch(buf[i])
101 | {
102 | case 0x0A:
103 | case 0x0D:
104 | buf[i] = 0;
105 | break;
106 |
107 | default:
108 | done = 1;
109 | break;
110 | }
111 | }
112 |
113 | buf[charsRead] = 0;
114 |
115 | return charsRead;
116 | }
117 |
--------------------------------------------------------------------------------
/common/IConsole.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "common/ITypes.h"
4 | #include "common/ISingleton.h"
5 | #include
6 |
7 | /**
8 | * Wrapper class for a standard Windows console
9 | *
10 | * @todo make nonblocking
11 | */
12 | class IConsole : public ISingleton
13 | {
14 | public:
15 | IConsole();
16 | ~IConsole();
17 |
18 | void Write(char * buf);
19 | void Write(char * buf, UInt32 bufLen, const char * fmt, ...);
20 |
21 | char ReadChar(void);
22 | UInt32 ReadBuf(char * buf, UInt32 len);
23 |
24 | private:
25 | HANDLE inputHandle, outputHandle;
26 | };
27 |
--------------------------------------------------------------------------------
/common/ICriticalSection.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if 0
4 |
5 | class ICriticalSection
6 | {
7 | public:
8 | ICriticalSection() { InitializeCriticalSection(&critSection); }
9 | ~ICriticalSection() { DeleteCriticalSection(&critSection); }
10 |
11 | void Enter(void) { EnterCriticalSection(&critSection); }
12 | void Leave(void) { LeaveCriticalSection(&critSection); }
13 | bool TryEnter(void) { return TryEnterCriticalSection(&critSection) != 0; }
14 |
15 | private:
16 | CRITICAL_SECTION critSection;
17 | };
18 |
19 | class ScopedLock
20 | {
21 | public:
22 | ScopedLock(ICriticalSection& critSection) : m_critSection(critSection)
23 | {
24 | m_critSection.Enter();
25 | }
26 |
27 | ~ScopedLock()
28 | {
29 | m_critSection.Leave();
30 | }
31 |
32 | private:
33 | ICriticalSection& m_critSection;
34 | };
35 |
36 | #else
37 |
38 | class ICriticalSection
39 | {
40 | DWORD owningThread;
41 | DWORD enterCount;
42 |
43 | public:
44 | ICriticalSection() : owningThread(0), enterCount(0) {}
45 |
46 | void Enter()
47 | {
48 | DWORD currThread = GetCurrentThreadId();
49 | if (owningThread == currThread)
50 | {
51 | enterCount++;
52 | return;
53 | }
54 | if (InterlockedCompareExchange(&owningThread, currThread, 0))
55 | {
56 | DWORD fastIdx = 10000;
57 | do {
58 | Sleep(--fastIdx >> 0x1F);
59 | } while (InterlockedCompareExchange(&owningThread, currThread, 0));
60 | }
61 | enterCount = 1;
62 | }
63 |
64 | __forceinline void Leave()
65 | {
66 | if (!--enterCount)
67 | owningThread = 0;
68 | }
69 | };
70 |
71 | class ScopedLock
72 | {
73 | ICriticalSection *m_cs;
74 |
75 | public:
76 | ScopedLock(ICriticalSection &cs) : m_cs(&cs) {cs.Enter();}
77 | ~ScopedLock() {m_cs->Leave();}
78 | };
79 |
80 | #endif
--------------------------------------------------------------------------------
/common/IDataStream.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "common/IErrors.h"
4 |
5 | /**
6 | * An arbitrary data stream
7 | */
8 | class IDataStream
9 | {
10 | public:
11 | IDataStream();
12 | virtual ~IDataStream();
13 |
14 | // read
15 | virtual UInt8 Read8(void);
16 | virtual UInt16 Read16(void);
17 | virtual UInt32 Read32(void);
18 | virtual UInt64 Read64(void);
19 | virtual float ReadFloat(void);
20 | virtual UInt32 ReadString(char * buf, UInt32 bufLength, char altTerminator = 0, char altTerminator2 = 0);
21 | virtual void ReadBuf(void * buf, UInt32 inLength) = 0;
22 |
23 | // peek
24 | virtual UInt8 Peek8(void);
25 | virtual UInt16 Peek16(void);
26 | virtual UInt32 Peek32(void);
27 | virtual UInt64 Peek64(void);
28 | virtual float PeekFloat(void);
29 | virtual void PeekBuf(void * buf, UInt32 inLength);
30 |
31 | virtual void Skip(SInt64 inBytes);
32 |
33 | // write
34 | virtual void Write8(UInt8 inData);
35 | virtual void Write16(UInt16 inData);
36 | virtual void Write32(UInt32 inData);
37 | virtual void Write64(UInt64 inData);
38 | virtual void WriteFloat(float inData);
39 | virtual void WriteString(const char * buf);
40 | virtual void WriteBuf(const void * buf, UInt32 inLength) = 0;
41 |
42 | SInt64 GetLength(void);
43 | SInt64 GetRemain(void);
44 | SInt64 GetOffset(void);
45 | bool HitEOF(void);
46 |
47 | virtual void SetOffset(SInt64 inOffset);
48 | void Rewind(void) { SetOffset(0); }
49 |
50 | void SwapBytes(bool inSwapBytes);
51 |
52 | virtual SInt64 GetParentOffset(void) { return GetOffset(); }
53 | virtual IDataStream * GetParent(void) { return NULL; }
54 |
55 | IDataStream * GetRootParent(void);
56 |
57 | static void CopyStreams(IDataStream * out, IDataStream * in, UInt64 bufferSize = 1024 * 1024, UInt8 * buf = NULL);
58 | static void CopySubStreams(IDataStream * out, IDataStream * in, UInt64 remain, UInt64 bufferSize = 1024 * 1024, UInt8 * buf = NULL);
59 |
60 | protected:
61 | SInt64 streamLength;
62 | SInt64 streamOffset;
63 | bool swapBytes;
64 | };
65 |
66 | /**
67 | * A utility class to automatically save and restore the current position of an IDataStream
68 | */
69 | class IDataStream_PositionSaver
70 | {
71 | public:
72 | IDataStream_PositionSaver(IDataStream * tgt);
73 | ~IDataStream_PositionSaver();
74 |
75 | private:
76 | IDataStream * stream;
77 | SInt64 offset;
78 | };
79 |
80 | class IDataSubStream : public IDataStream
81 | {
82 | public:
83 | IDataSubStream();
84 | IDataSubStream(IDataStream * inStream, SInt64 inOffset, SInt64 inLength);
85 | ~IDataSubStream();
86 |
87 | void Attach(IDataStream * inStream, SInt64 inOffset, SInt64 inLength);
88 |
89 | void ReadBuf(void * buf, UInt32 inLength);
90 | void WriteBuf(const void * buf, UInt32 inLength);
91 | void SetOffset(SInt64 inOffset);
92 |
93 | virtual SInt64 GetParentOffset(void) { return stream->GetOffset(); }
94 | virtual IDataStream * GetParent(void) { return stream; }
95 |
96 | SInt64 GetSubBase(void) { return subBase; }
97 |
98 | private:
99 | IDataStream * stream;
100 |
101 | SInt64 subBase;
102 | };
103 |
--------------------------------------------------------------------------------
/common/IDatabase.cpp:
--------------------------------------------------------------------------------
1 | #include "IDatabase.h"
2 |
--------------------------------------------------------------------------------
/common/IDatabase.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include