1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | int DataTable::AddBinary( const void *buffer, int size ){
|
---|
4 | int retSize = this->size;
|
---|
5 |
|
---|
6 | Realloc( this->size + size );
|
---|
7 | memcpy( (char *)this->buffer + retSize, buffer, size );
|
---|
8 |
|
---|
9 | return retSize;
|
---|
10 | }
|
---|
11 | int DataTable::Add( _int64 i64data ){
|
---|
12 | int retSize = size;
|
---|
13 | AddBinary( &i64data, sizeof( _int64 ) );
|
---|
14 | return retSize;
|
---|
15 | }
|
---|
16 | int DataTable::Add( int i32data ){
|
---|
17 | int retSize = size;
|
---|
18 | AddBinary( &i32data, sizeof( int ) );
|
---|
19 | return retSize;
|
---|
20 | }
|
---|
21 | int DataTable::Add( double dbl ){
|
---|
22 | int retSize = size;
|
---|
23 | AddBinary( &dbl, sizeof( double ) );
|
---|
24 | return retSize;
|
---|
25 | }
|
---|
26 | int DataTable::Add( float flt ){
|
---|
27 | int retSize = size;
|
---|
28 | AddBinary( &flt, sizeof( float ) );
|
---|
29 | return retSize;
|
---|
30 | }
|
---|
31 | int DataTable::AddString( const char *str, int length ){
|
---|
32 | int retSize = size;
|
---|
33 |
|
---|
34 | if( compiler.IsUnicode() ){
|
---|
35 | //Shift-JIS → Unicode
|
---|
36 | int size = MultiByteToWideChar(
|
---|
37 | CP_ACP,
|
---|
38 | 0,
|
---|
39 | str, length + 1,
|
---|
40 | NULL, 0 ) * 2;
|
---|
41 |
|
---|
42 | LPWSTR pwstr = (LPWSTR)malloc( size );
|
---|
43 |
|
---|
44 | MultiByteToWideChar(
|
---|
45 | CP_ACP,
|
---|
46 | 0,
|
---|
47 | str, length + 1,
|
---|
48 | pwstr, length + 1 );
|
---|
49 |
|
---|
50 | AddBinary( pwstr, size );
|
---|
51 |
|
---|
52 | free( pwstr );
|
---|
53 | }
|
---|
54 | else{
|
---|
55 | AddBinary( str, length + 1 );
|
---|
56 | }
|
---|
57 |
|
---|
58 | return retSize;
|
---|
59 | }
|
---|
60 | int DataTable::AddString( const char *str )
|
---|
61 | {
|
---|
62 | return AddString( str, lstrlen( str ) );
|
---|
63 | }
|
---|
64 | int DataTable::AddString( const std::string &str )
|
---|
65 | {
|
---|
66 | return AddString( str.c_str(), static_cast<int>(str.length()) );
|
---|
67 | }
|
---|
68 | int DataTable::AddSpace( int size )
|
---|
69 | {
|
---|
70 | int retSize = this->size;
|
---|
71 | Realloc( this->size + size );
|
---|
72 | return retSize;
|
---|
73 | }
|
---|
74 | void DataTable::AddAlignment( int size )
|
---|
75 | {
|
---|
76 | if( this->size % size == 0 )
|
---|
77 | {
|
---|
78 | // 既に境界のとき
|
---|
79 | return;
|
---|
80 | }
|
---|
81 | Realloc( this->size + ( size - (int)(this->size%size) ) );
|
---|
82 | }
|
---|
83 |
|
---|
84 | void DataTable::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
|
---|
85 | {
|
---|
86 | BOOST_FOREACH( const Schedule &schedule, schedules )
|
---|
87 | {
|
---|
88 | if( schedule.GetType() == Schedule::DataTable )
|
---|
89 | {
|
---|
90 | #ifdef _WIN64
|
---|
91 | OverwriteInt64(
|
---|
92 | schedule.GetOffset(),
|
---|
93 | GetInt64( schedule.GetOffset() ) + dataSectionBaseOffset
|
---|
94 | );
|
---|
95 | #else
|
---|
96 | Overwrite(
|
---|
97 | schedule.GetOffset(),
|
---|
98 | GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
|
---|
99 | );
|
---|
100 | #endif
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|